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 8539683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:25:29+00:00 2026-06-11T11:25:29+00:00

I am a newbie to MVVM. I have two grid’s inside by main window

  • 0

I am a newbie to MVVM. I have two grid’s inside by main window where one grid contains a listbox towards left side and other grid on the right side contains list view and 2 buttons.

I am able to add items to listview and even figure out how to get the selected item from list view. Once I select the item on list view and click a button(Connect), listbox towards left shud get updated with items which I have added from viewmodel class.

View below shows Listbox towards my left:

<Grid Grid.Column="0" Name="BoardTabSelect" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
    <ListBox Name="ButtonPanel" 
             ItemsSource="{Binding BoardTabs, Mode=TwoWay}" 
             SelectedItem="{Binding SelectedTab, Mode=TwoWay}" >
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Name="BoardtabChanger" 
                               Margin="53,27,0,0" 
                               Text="{Binding TabOperation}" />
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>

View below shows listview towards Right along with 2 Buttons:

<Grid Grid.Row="0" Name="MainConnectGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
    <ListView Name="listView" 
              ItemsSource="{Binding Products}" 
              SelectedItem="{Binding SelectedProduct, Mode=TwoWay}">
        <ListView.View>
            <GridView>
                <GridViewColumn Width="300" 
                                Header="Name" 
                                DisplayMemberBinding="{Binding Name}" />
                <GridViewColumn Width="283" 
                                Header="Connection Status" 
                                DisplayMemberBinding="{Binding Connection_Status}" />
            </GridView>
        </ListView.View>
    </ListView>

    <Button Content="Connect" 
            Height="23" Width="100" 
            HorizontalAlignment="Left" VerticalAlignment="Top"
            Margin="55,519,0,0" 
            Name="ConnectBtnGrid"  
            Command="{Binding Path=ConnectCommand}" />                        
    <Button Content="Disconnect" 
            Height="23" Width="100"
            HorizontalAlignment="Left" VerticalAlignment="Top" 
            Margin="446,519,0,0" 
            Name="DisconnectBtn" 
            Command="{Binding Path=DisconnectCommand}" />
</Grid>

VIEW MODEL:

public class ProductViewModel : INotifyPropertyChanged 
{
    public List<Product> m_Products;
    public List<Product> m_BoardTabs;                

    public ProductViewModel()
    {           
        m_Products = new List<Product>()
        {                
            new Product() {Name = "Bavaria", Connection_Status = "Disconnected"},
            new Product() {Name = "Redhook", Connection_Status = "Disconnected"},                
        };

        m_BoardTabs = new List<Product>()
        {
            new Product() {TabOperation = "Connect"}                 
        };
    }                      

    public List<Product> Products { get; set; }

    public List<Product> BoardTabs { get; set; }

    private Product m_SelectedItem;
    public Product SelectedProduct
    {
        get { return m_SelectedItem; }

        set
        {
            m_SelectedItem = value;                
            NotifyPropertyChanged("SelectedProduct");
        }
    }

    private Product m_SelectedTab;
    public Product SelectedTab
    {
        get { return m_SelectedTab; }

        set
        {
            m_SelectedTab = value;
            NotifyPropertyChanged("SelectedTab");                
        }
    }

    private ICommand mUpdater;
    public ICommand ConnectCommand
    {
        get
        {
            if (mUpdater == null)
                mUpdater = new DelegateCommand(new Action(SaveExecuted), new Func<bool>(SaveCanExecute));

            return mUpdater;
        }
        set { mUpdater = value; }
    }

    public bool SaveCanExecute()
    {
        return true;
    }     

    public void SaveExecuted()
    {
        if (SelectedProduct.Connection_Status == "Disconnected" && SelectedProduct.Name == "Bavaria")
        {
            SelectedProduct.Connection_Status = "Connected";
            m_BoardTabs.Add(new Product() { TabOperation = "I2C" });         
            m_BoardTabs.Add(new Product() { TabOperation = "Voltage" });    
            m_BoardTabs.Add(new Product() { TabOperation = "Codec" });   
        }
    }
}

Inside the Save Executed method I am trying to add the items in listbox but when I run the application and select item from listview and press CONNECT Btn, the list does not get updated. My model class is complete with all three properties (Name, Connection Status and TabOperation)

  • 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-11T11:25:30+00:00Added an answer on June 11, 2026 at 11:25 am

    BoardTabs and Products need to be an ObservableCollection<Product>. Otherwise WPF doesn’t get informed about new items in the lists and thus can’t update the UI.

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

Sidebar

Related Questions

newbie doing Java homework here. I have one class named Album which contains the
Newbie question... So I have two activities, Cherry and Apple, and each one has
I am a complete newbie to WPF and MVVM so I apologise in advance
newbie here, so thanks in advance for help! I have a Wordpress site with
Newbie question... The objective: I intend to have an HTML text input field as
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
newbie programmer here. I have 3 tables namely product, category, and subcategory. I configured
Newbie question here but for some reason I cant figure this out. I have
Newbie asking for help: I have an array of numbers that needs to be
Newbie question. I’m writing an ASP.Net MVC app in VB.Net and have been using

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.