从列表中选择项目并将其添加到列表中
本文关键字:列表 添加 项目 选择 | 更新日期: 2023-09-27 17:58:58
嗨,我正在开发一个网络应用程序,我正在使用C#WPF和MVVM模式。这将是一个快速配置应用程序,以便用户可以从应用程序配置设备。混淆的问题是,我想获取有关vlan的信息,并且用户可以创建多个vlan。因此,我需要同时从用户那里获取多个信息,最后我将通过telnet命令配置所有值。从用户那里获取多个输入并将其存储到最后,以便正确配置的可能而简单的方法是什么?建议将是非常可观的。
我的VLANS ViewModel代码是:
public class VLANSViewModel : WizardPageViewModelBase
{
#region Fields
#endregion // end region fields
#region Constructor
public VLANSViewModel(ConfigurationLibrary configuration)
: base(configuration)
{
VlanIP1 = "192";
VlanIP2 = "168";
VlanIP3 = "1";
VlanIP4 = "1";
}
#endregion
#region Properties
public string VlanName
{
get
{
return this.ConfigurationLibrary.ConfigLibraryVlanName;
}
set
{
if (String.Equals(this.ConfigurationLibrary.ConfigLibraryVlanName, value))
{
return;
}
this.ConfigurationLibrary.ConfigLibraryVlanName = value;
this.OnPropertyChanged("VlanName");
}
}
public string VlanID
{
get
{
return this.ConfigurationLibrary.ConfigLibraryVlanName;
}
set
{
if (String.Equals(this.ConfigurationLibrary.ConfigLibraryVlanName, value))
{
return;
}
this.ConfigurationLibrary.ConfigLibraryVlanName = value;
this.OnPropertyChanged("VlanID");
}
}
public string VlanIP1
{
get
{
return this.ConfigurationLibrary.ConfigLibraryVlanIp1;
}
set
{
if (!String.Equals(this.ConfigurationLibrary.ConfigLibraryVlanIp1, value))
{
this.ConfigurationLibrary.ConfigLibraryVlanIp1 = value;
this.OnPropertyChanged("VlanIP1");
}
}
}
public string VlanIP2
{
get
{
return this.ConfigurationLibrary.ConfigLibraryVlanIp2;
}
set
{
if (!String.Equals(this.ConfigurationLibrary.ConfigLibraryVlanIp2, value))
{
this.ConfigurationLibrary.ConfigLibraryVlanIp2 = value;
this.OnPropertyChanged("VlanIP2");
}
}
}
public string VlanIP3
{
get
{
return this.ConfigurationLibrary.ConfigLibraryVlanIp3;
}
set
{
if (!String.Equals(this.ConfigurationLibrary.ConfigLibraryVlanIp3, value))
{
this.ConfigurationLibrary.ConfigLibraryVlanIp3 = value;
this.OnPropertyChanged("VlanIP3");
}
}
}
public string VlanIP4
{
get
{
return this.ConfigurationLibrary.ConfigLibraryVlanIp4;
}
set
{
if (!String.Equals(this.ConfigurationLibrary.ConfigLibraryVlanIp4, value))
{
this.ConfigurationLibrary.ConfigLibraryVlanIp4 = value;
this.OnPropertyChanged("VlanIP4");
}
}
}
public string VlanDefaultRoute1
{
get
{
return this.ConfigurationLibrary.ConfigLibraryVlanDefaultRoute1;
}
set
{
if (!String.Equals(this.ConfigurationLibrary.ConfigLibraryVlanDefaultRoute1, value))
{
this.ConfigurationLibrary.ConfigLibraryVlanDefaultRoute1 = value;
this.OnPropertyChanged("VlanDefaultRoute1");
}
}
}
public string VlanDefaultRoute2
{
get
{
return this.ConfigurationLibrary.ConfigLibraryVlanDefaultRoute2;
}
set
{
if (!String.Equals(this.ConfigurationLibrary.ConfigLibraryVlanDefaultRoute2, value))
{
this.ConfigurationLibrary.ConfigLibraryVlanDefaultRoute2 = value;
this.OnPropertyChanged("VlanDefaultRoute2");
}
}
}
public string VlanDefaultRoute3
{
get
{
return this.ConfigurationLibrary.ConfigLibraryVlanDefaultRoute3;
}
set
{
if (!String.Equals(this.ConfigurationLibrary.ConfigLibraryVlanDefaultRoute3, value))
{
this.ConfigurationLibrary.ConfigLibraryVlanDefaultRoute3= value;
this.OnPropertyChanged("VlanDefaultRoute3");
}
}
}
public string VlanDefaultRoute4
{
get
{
return this.ConfigurationLibrary.ConfigLibraryVlanDefaultRoute4;
}
set
{
if (!String.Equals(this.ConfigurationLibrary.ConfigLibraryVlanDefaultRoute4, value))
{
this.ConfigurationLibrary.ConfigLibraryVlanDefaultRoute4 = value;
this.OnPropertyChanged("VlanDefaultRoute4");
}
}
}
#endregion // end region fields
public override string DisplayName
{
get
{
return Strings.PageDisplayName_VLAN;
}
}
#region Methods
internal override bool IsValid()
{
return true;
}
#endregion
}
我对VLANS的看法是:
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label
Grid.Row="0"
Grid.Column="0"
VerticalAlignment="Center"
Content="VLAN NAME"
Foreground="Black"
Opacity="0.8"
/>
<ComboBox
Grid.Row="0"
Grid.Column="1"
Margin="0,5,0,0"
Height="25"
Foreground="Black"
Opacity="0.8"
Width="Auto"
Text="{Binding VlanName, UpdateSourceTrigger=PropertyChanged}"
/>
<Label
Grid.Row="1"
Grid.Column="0"
VerticalAlignment="Center"
Content="VLAN ID"
Foreground="Black"
Opacity="0.8"
/>
<TextBox
Grid.Row="1"
Grid.Column="1"
Margin="0,5,0,0"
Height="25"
Foreground="Black"
Opacity="0.8"
Width="Auto"
Text="{Binding VlanID, UpdateSourceTrigger=PropertyChanged}"
/>
<Label
Grid.Row="2"
Grid.Column="0"
VerticalAlignment="Center"
Content="IP FOR VLAN"
Foreground="Black"
Opacity="0.8"
/>
<Grid
Grid.Column="1"
Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
<TextBox
Grid.Row="2"
Grid.Column="0"
Margin="5"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding VlanIP1, UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox
Grid.Row="2"
Grid.Column="1"
Margin="5"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding VlanIP2, UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox
Grid.Row="2"
Grid.Column="2"
Margin="5"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding VlanIP3, UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox
Grid.Row="2"
Grid.Column="3"
Margin="5"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding VlanIP4, UpdateSourceTrigger=PropertyChanged}"
/>
</Grid>
<Label
Grid.Row="3"
Grid.Column="0"
VerticalAlignment="Center"
Content="DEFAULT ROUTE"
Foreground="Black"
Opacity="0.8"
/>
<Grid
Grid.Row="3"
Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
<TextBox
Grid.Row="2"
Grid.Column="0"
Margin="5"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding VlanDefaultRoute1, UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox
Grid.Row="2"
Grid.Column="1"
Margin="5"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding VlanDefaultRoute2, UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox
Grid.Row="2"
Grid.Column="2"
Margin="5"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding VlanDefaultRoute3, UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox
Grid.Row="2"
Grid.Column="3"
Margin="5"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding VlanDefaultRoute4, UpdateSourceTrigger=PropertyChanged}"
/>
</Grid>
</Grid>
</UserControl>
我想一次为VLANS值保存多个值。现在有什么建议吗?
我认为您正在寻找一个很好的入门,以便从头开始了解能够正确处理模型的MVVM应用程序。在这种情况下,我建议使用"开始使用MVVM"guid,例如Catel中的这个。