2012-10-04 1 views
1

나는 작업중인 프로그램의 ViewModel을 파악하려고합니다. 나는 전에 이것을 한 적이 없다. 다음은 ViewModel이 필요한 Switch 개체의 부분 클래스 정의와 지금까지 가지고있는 XAML입니다. 나는 XAML이 더 많이 필요하다는 것을 알고있다.처음으로 ViewModel 빌드

지금 바로 열기 전에 데이터로 SwitchBrowser 창을 채우기 위해 코드 숨김 작업을하고 있습니다. ObservableCollection을 XAML에 바인딩하는 것이 더 쉽다는 것을 알고 있습니다.

ObservableCollectionCiscoSwitch 개체를 저장하고 Switch 개체의 속성에 직접 바인딩 할 수 있습니까?

그렇다면, 나는 CiscoSwitchModulesList에 XAML에 ModulesTreeviewItemsSource을 설정하는 등의 일을 할 수 있습니까? 지금은 ModulesTreeView을 채우기 위해 코드 숨김에 foreach를 사용하고 있습니다.

ObservableCollectionSwitchModules으로 작성한 다음 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 : 단일 ObservableCollection<CiscoSwitch>를 만드는 방법에 대한

<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> 

답변

2

첫 번째 아이디어는 갈 올바른 방법입니다. 다음은 특정 요구 사항까지 확장 할 수있는보다 간단한 예제입니다.

public class Person 
{ 
    public string Name { get; set; } 
    public string Address { get; set; } 
} 

은 우리가 ObservableCollection<Person>People라는이 우리의 ViewModel에서 해당 가정합니다.

<ListBox ItemsSource="{Binding Path=People}"> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <StackPanel Orientation="Horizontal"> 
       <TextBlock Text="{Binding Path=Name}" /> 
       <TextBlock Text="{Binding Path=Address}" /> 
      </StackPanel> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

이것은 너무 단순화 된 예이지만 필요에 따라 확장 할 수 있어야한다고 생각합니다. 희망이 도움이!

+0

감사합니다. 나는 그것의 일부가 작동하도록했다. –

+0

기꺼이 도와 드리겠습니다. –