I want to display a List/ObservableCollection in a DataGrid in a WPF application. At the push of a button, a different list should be displayed, but it is a list of a different data type. It works without databinding, but I would like to change the GUI to MVVM/Databinding.
XAML:
<DataGrid ItemsSource="{Binding MyList}" Width="400" />
Example Code:
public void test(bool changeList)
{
ObservableCollection<type1> list1 = new ObservableCollection<type1>();
ObservableCollection<type2> list2 = new ObservableCollection<type2>();
ObservableCollection<T> MyList;
if (changeList)
{
MyList = list1;
}
else
{
MyList = list2;
}
}
I know I still need to use RaisePropertyChanges, etc.
How can I access a general list/ObservableCollection?
Without databinding, I got the desired result:
xml:
<DataGrid x:Name="dataGrid" IsReadOnly="{Binding Path=IsChecked, ElementName=CbDisableList}" CurrentCellChanged="DGChangedList"/>
Example Code
if (changeList)
{
dataGrid.ItemsSource = list1;
}
else
{
dataGrid.ItemsSource = list2;
}
Wirthi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1