Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

VB.NET / WPF Serialisierung

Empfohlene Antworten

Veröffentlicht

Hallo liebe Community,

ich habe ein kleiner Problem mit der Serialisierung von Feldern in VB.NET / WPF.

Ich habe mir eine Klasse geschrieben die jedes mal, wenn die eigenschaften eines Programms gespeichert werden (per Button) oder wenn etwas in eine Textbox eingetragen wird, speichern soll.

Hier mal die Klasse:


Public Class SASerializerXml


    Public Shared Sub Serialize(Of T)(ByVal path As String, ByVal instance As T)


        Try

            Dim swWriter As New StreamWriter(path)

            Dim xsSerializer As New XmlSerializer(instance.GetType)


            xsSerializer.Serialize(swWriter, instance)

            swWriter.Close()

        Catch ex As Exception

            'MessageBox.Show(ex.Message, Application.ProductName, _

            '  MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub


    Public Shared Function DeSerialize(Of T)(ByVal path As String, ByVal defaultInstance As T) As T


        Try

            If Not File.Exists(path) Then

                Return defaultInstance

            End If

            Dim srReader As New StreamReader(path)

            Dim xsSerializer As New XmlSerializer(defaultInstance.GetType)


            DeSerialize = CType(xsSerializer.Deserialize(srReader), T)

            srReader.Close()

        Catch ex As Exception

            'MessageBox.Show(ex.Message, Application.ProductName, _

            '  MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Function


    Public Shared Function DeSerialize(Of T As New)(ByVal path As String) As T

        Return DeSerialize(Of T)(path, New T)

    End Function

End Class

Hier noch ein Textfeld mit Binding:


 <Label Content="Eingangsverzeichnis:" Grid.ColumnSpan="3" Height="28" HorizontalAlignment="Left" Margin="10,10,0,0" Name="Label8" VerticalAlignment="Top" Width="130" />

                            <TextBox Grid.Column="2" Height="23" HorizontalAlignment="Left" Margin="104,15,0,0" Name="tbDPDEin" Text="{Binding Source={x:Static me:MySettings.Default}, Path=DPDEin, Mode=TwoWay}" VerticalAlignment="Top" Width="120" />

Jetzt ergibt sich allerdings folgendes Problem:

Wenn ich so etwas in die Felder reinschreibe & abspeichere funktioniert das super...wenn ich allerdings etwas auswähle (Bsp. über FileDialog o.ä.) wird in das Feld ja automatisch etwas eingefügt und dass speichert er dann nicht mit ab.

Hat jemand eine Idee was ich da falsch mache ?

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.