1

I am new in WPF and MVVM. I have two list List A and List B.First List contains many items and second list contains few item. Every item in list A execute sequentially.First item will send command to printer and will get response from printer,if response matches then it will move to next.

Item form List A send one command or Multiple command.

So,now i want to check whether item send one command or multiple command.If it is sending multiple command then i want to display all item of from B list below to respective A's list and data binding for that.

For Single command my code is working fine

Note:List B varies from item to item.

Following are the properties i used in my code:

     private bool isMultiCommand;
    public bool IsMultiCommand 
    {
        get { return isMultiCommand; }
        set { SetProperty(ref isMultiCommand, value)};
    }


    public List<TestItem> MultipleCommandTestItemsList { get; set; }

     public string TestItemName { get; set; }


    private List<TestItem> testItemsList;
    public List<TestItem> TestItemsList
    { 
         get { return testItemsList; } 
         set { SetProperty(ref testItemsList, value); }
    }

This is my .xaml code

1
  • 3
    Use ObservableCollection if you want binding to update using lists, (google is your friend) Commented Mar 20, 2017 at 10:10

2 Answers 2

1

To update collection and it's items you should use ObservableCollection<TestItem> instead of List<TestItem>. TestItem should also implement INotifyPropertyChanged to notify when it changes.

Sign up to request clarification or add additional context in comments.

Comments

1

XAML Design:

<Grid>

    <ListBox x:Name="Listbox1" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100"/>

    <Button x:Name="Add" Content="ADD" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="105,10,0,0" Click="Add_Click"/>

    <Button Content="REMOVE" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="105,45,0,0" Click="Remove_Click"/>

    <Label Content="Add Listitem" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="105,74,0,0"/>
    <TextBox x:Name="textbox1" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="84" Margin="105,100,0,0"/>

</Grid>

XAML Design.cs

Add Namespace: using System.Collections.ObjectModel;

private ObservableCollection<string> listitem;
    public Window5()
    {
        InitializeComponent();
        listitem = new ObservableCollection<string> { "ListItem 1", "ListItem 2" };
        Listbox1.ItemsSource = listitem;
    }

    private void Add_Click(object sender, RoutedEventArgs e)
    {
        listitem.Insert(listitem.Count, textbox1.Text);
        textbox1.Clear();
    }

    private void Remove_Click(object sender, RoutedEventArgs e)
    {
        int index = Listbox1.SelectedIndex;
        listitem.RemoveAt(Listbox1.SelectedIndex);
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.