我正在尝试为我正在处理的程序找出 ViewModel。我以前没有这样做过。Switch
这是需要的对象的部分类定义ViewModel
和我目前拥有的 XAML。我知道 XAML 需要更多。
现在我正在做代码隐藏,在SwitchBrowser
打开窗口之前用数据填充窗口。我知道将 an 绑定ObservableCollection
到 XAML 会更容易。
我可以将对象存储在一个CiscoSwitch
对象中ObservableCollection
并直接绑定到Switch
对象的属性吗?
如果是这样,我可以执行类似将XAML 中的on 设置为 on 的操作ItemsSource
吗?现在我在代码隐藏中使用 foreach 来填充. ModulesTreeview
ModulesList
CiscoSwitch
ModulesTreeView
或者,我会创建一个ObservableCollection
of SwitchModules
,然后创建另一个 for VSANs
,等等?
public partial class CiscoSwitch
{
#region baseswitchclassproperties
private string _SwitchName = String.Empty;
public string switchName{ get{return _SwitchName;} set{_SwitchName=value;} } private string _SWVersion = String.Empty;
public string swVersion{ get{return _SWVersion;} set{_SWVersion=value;} }
private string _SwitchModel = String.Empty;
public string switchModel { get{return _SwitchModel;} set{_SwitchModel=value;} }
private string _SerialNumber = String.Empty;
public string SerialNumber { get { return _SerialNumber; } set { _SerialNumber = value; } }
private string _SwitchWWPN = string.Empty;
public string SwitchWWPN { get { return _SwitchWWPN; } set { _SwitchWWPN = value; } }
public Dictionary<int, SwitchModule> ModuleList = new Dictionary<int, SwitchModule>();
public Dictionary <int, CiscoVSAN> VSANList = new Dictionary<int, CiscoVSAN>();
protected EthernetPort _ManagementPort = new EthernetPort();
public string IPAddress{ set{_ManagementPort.IPAddress=value;} get{return _ManagementPort.IPAddress;} }
public string LastDataCaptureDate = null;
public Dictionary<int, PortChannel> PortChanelList = new Dictionary<int, PortChannel>();
public Dictionary<String, FCIPPort> FCIPPortList = new Dictionary<string, FCIPPort>();
public InterVSANTopology IVRTopology = null; //new InterVSANTopology();
public Dictionary<int, List<CiscoSwitch>> NeighborsList = new Dictionary<int, List<CiscoSwitch>>();
public Dictionary<string, string> DeviceAliases = new Dictionary<string, string>();
public Dictionary<string, FCPort> FlogiDatabase = new Dictionary<string, FCPort>();
#endregion
}
XAML:
<Window.Resources>
<Style TargetType="{x:Type TreeViewItem}" x:Key="ModuleStyle">
<Setter Property="Foreground" Value="Blue"/>
<Setter Property="FontSize" Value="12"/>
</Style>
<Style TargetType="{x:Type TreeViewItem}" x:Key="RedModuleStyle" BasedOn="{StaticResource ModuleStyle}">
<Setter Property="Foreground" Value="Red"/>
</Style>
</Window.Resources>
<Grid Margin="0,0,-211.4,-168">
<StackPanel HorizontalAlignment="Stretch" Name="StackPanel1" VerticalAlignment="Stretch" Width="Auto" Margin="0,0,188.6,114">
<StackPanel.Resources>
<Style TargetType="{x:Type Label}" x:Key="LabelStyle">
<Setter Property="Foreground" Value="Blue"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontWeight" Value="Bold"/>
</Style>
</StackPanel.Resources>
<Label Content="Switch Name:" Name="Label1" Height="25" HorizontalAlignment="Left"/>
<Label Content="Software Version:" Name="Label2" HorizontalAlignment="Left" />
<Label Content="Model Number:" Name="Label3" HorizontalAlignment="left"/>
<Label Content="IP Address:" Name="Label4" HorizontalAlignment="left"></Label>
<Label Content="Serial Number:" Name="Label5" HorizontalAlignment="Left"></Label>
<Label Content="Show Tech Taken:" Name="Label6" HorizontalAlignment="left"/>
</StackPanel>
<StackPanel Margin="105,0,15.6,114">
<StackPanel.Resources>
<Style TargetType="{x:Type Label}" x:Key="LabelStyle">
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontWeight" Value="Bold"/>
</Style>
</StackPanel.Resources>
<Label Content="Name" Name="SwitchNameLabel" HorizontalAlignment="left"/>
<Label Content="Version" Name="VersionLabel" HorizontalAlignment="left"/>
<Label Content="Model" Name="ModelNumberLabel" HorizontalAlignment="Left"/>
<Label Content="IP" Name="IPAddressLabel" HorizontalAlignment="Left"/>
<Label Content="Serial" Name="SerialLabel" HorizontalAlignment="Left"/>
<Label Content="ST" Name="ShowTechLabel" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel HorizontalAlignment="Left" Height="Auto" Margin="0,156,0,0" VerticalAlignment="Top" Width="256" >
<TreeView Name="ModulesTreeView" Height="auto" Background="GhostWhite" BorderThickness="0"/>
</StackPanel>
</Grid>