Я создал набор данных во время разработки в Project-> Add New Items-> Settings.xsd. Затем я создал две таблицы данных с именами LANSettings и WANSettings, со столбцами для IP-адреса и тому подобное. Я получил идею при использовании форм Windows. К сожалению, когда дело доходит до wpf, реализация немного отличается. Я пытался выучить набор данных в xml, и я могу его создать, но именно тогда набор данных создается в коде позади.
Я пытался выучить набор данных и xml в Интернете, но все, что они показывают, относится к языку c #. Как я могу сделать это при использовании набора данных во время разработки?
вот неполный код:
MainWindow.xaml.vb
Imports System.Xml
Imports System.Data
Imports datasettrials
Class MainWindow
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs) Handles MyBase.Loaded
Dim Settings As datasettrials.Settings = CType(Me.FindResource("Settings"), datasettrials.Settings)
End Sub
Private Sub ApplyButton_Click(sender As Object, e As RoutedEventArgs) Handles ApplyButton.Click
End Sub
Private Sub WriteXmlToFile(thisDataSet As Settings)
If thisDataSet Is Nothing Then
Return
End If
Dim filename As String = "xmlSettings.xml"
Dim stream As New System.IO.FileStream(filename, System.IO.FileMode.Create)
Dim xmlwriter As New XmlTextWriter(stream, System.Text.Encoding.Unicode)
thisDataSet.WriteXml(xmlwriter)
xmlwriter.Close()
End Sub
End Class
MainWindow.xaml
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:datasettrials"
mc:Ignorable="d"
Title="MainWindow" Height="343.2" Width="509.6">
<Window.Resources>
<local:Settings x:Key="Settings"/>
<CollectionViewSource x:Key="LANSettingsViewSource" Source="{Binding LANSettings, Source={StaticResource Settings}}"/>
<CollectionViewSource x:Key="WANSettingsViewSource" Source="{Binding WANSettings, Source={StaticResource Settings}}"/>
</Window.Resources>
<Grid>
<GroupBox Header="LAN Settings" HorizontalAlignment="Left" Height="193" Margin="10,10,0,0" VerticalAlignment="Top" Width="231">
<Grid x:Name="Grid1" HorizontalAlignment="Left" Margin="4,12,0,0" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="IP address:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="0" VerticalAlignment="Center"/>
<TextBox x:Name="LanIPTextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="0" Text="{Binding LanIP, Mode=OneWayToSource, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
<Label Content="Subnet Mask:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="1" VerticalAlignment="Center"/>
<TextBox x:Name="LanSubnetTextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="1" Text="{Binding LanSubnet, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
<Label Content="Gateway:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="2" VerticalAlignment="Center"/>
<TextBox x:Name="LanGatewayTextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="2" Text="{Binding LanGateway, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
<Label Content="DNS 1:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="3" VerticalAlignment="Center"/>
<TextBox x:Name="LanDNS1TextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="3" Text="{Binding LanDNS1, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
<Label Content="DNS 2:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="4" VerticalAlignment="Center"/>
<TextBox x:Name="LanDNS2TextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="4" Text="{Binding LanDNS2, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
</Grid>
</GroupBox>
<GroupBox Header="WLAN Settings" HorizontalAlignment="Left" Height="258" Margin="246,10,0,0" VerticalAlignment="Top" Width="242">
<Grid x:Name="Grid2" DataContext="{StaticResource WANSettingsViewSource}" HorizontalAlignment="Left" Margin="4,8,0,-56.8" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="IP address:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="0" VerticalAlignment="Center"/>
<TextBox x:Name="WlanIPTextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="0" Text="{Binding WlanIP, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
<Label Content="Subnet Mask:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="1" VerticalAlignment="Center"/>
<TextBox x:Name="WlanSubnetTextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="1" Text="{Binding WlanSubnet, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
<Label Content="Gateway:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="2" VerticalAlignment="Center"/>
<TextBox x:Name="WlanGatewayTextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="2" Text="{Binding WlanGateway, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
<Label Content="DNS 1:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="3" VerticalAlignment="Center"/>
<TextBox x:Name="WlanDNS1TextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="3" Text="{Binding WlanDNS1, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
<Label Content="DNS 2:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="4" VerticalAlignment="Center"/>
<TextBox x:Name="WlanDNS2TextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="4" Text="{Binding WlanDNS2, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
<Label Content="SSID:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="5" VerticalAlignment="Center"/>
<TextBox x:Name="WlanSSIDTextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="5" Text="{Binding WlanSSID, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
<Label Content="Password:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="6" VerticalAlignment="Center"/>
<TextBox x:Name="WlanPassTextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="6" Text="{Binding WlanPass, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
</Grid>
</GroupBox>
<TextBlock x:Name="ipresulttextbox" HorizontalAlignment="Left" Margin="10,218,0,0" TextWrapping="Wrap" Text="{Binding LanIP}" VerticalAlignment="Top"/>
<Button x:Name="ApplyButton" Content="Apply" HorizontalAlignment="Left" Margin="10,239,0,0" VerticalAlignment="Top" Width="75"/>
</Grid>
</Window>