Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8655823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:07:58+00:00 2026-06-12T15:07:58+00:00

I am trying to figure out a ViewModel for a program I am working

  • 0

I am trying to figure out a ViewModel for a program I am working on. I have not done this before. Here is the partial class definition for the Switch object that needs the ViewModel and the XAML I have so far. I know the XAML needs more.

Right now I am doing code-behind to fill the SwitchBrowser window with data before I open it. I know it would be easier to bind an ObservableCollection to the XAML.

Can I store a CiscoSwitch object in an ObservableCollection and bind directly to the properties on the Switch object?

If so, can I do something like setting the ItemsSource on the ModulesTreeview in the XAML to the ModulesList on the CiscoSwitch? Right now I am using a foreach in the code-behind to fill the ModulesTreeView.

Or, would I create an ObservableCollection of SwitchModules, then another for VSANs, and so forth?

 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>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:07:59+00:00Added an answer on June 12, 2026 at 3:07 pm

    Your first idea about creating a single ObservableCollection<CiscoSwitch> is the correct way to go.
    Here is a more simplified example that you can extend to your specific needs.

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

    Assume that in our ViewModel we have an ObservableCollection<Person> called People.

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

    This is an oversimplified example, but I think you should be able to extend it to your needs. Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out why this isn't working... DomainModel public class ModelEntities :
trying to figure out why this is happening - I have an input text
I have a view that will look like this: I'm trying to figure out
I'm trying to figure out why this nested template doesn't display anything. I have
Trying to figure out how I can do this properly. The print_r looks like
Trying to figure out how to type (via events not set the value) on
This is probably a dumb question but I am trying to figure out how
Could someone help me with this issue. I'm trying to figure out how to
I've been trying to figure this out for quite some time now. I couldn't
I am still trying to figure out how to create reusable partial views in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.