简体   繁体   中英

Binding collection of collection to datagrid source in WPF MVVM Model

I have a view model in the following structure:

Viewmodel:
public System SystemLst
{
get;set;
}

Model:

public class System
{
    public ObservableCollection<Properties> PropertySource
        {
            get { return _dutPropertiesColl; }
            set { 
                _dutPropertiesColl = value;
                NotifyPropertyChanged("DUTPropertySource");
            }
        }


        public ObservableCollection<SubSystem> SubSystemList
        {
            get { return _subSystemList; }
            set
            {
                _subSystemList = value;
                NotifyPropertyChanged("SubsystemList");
            }
        }
}

public SubSystem SubSystemList
{
    public ObservableCollection<Test> TestLists
        {
          get;
      set;
        }
}

I have a WPF form with datacontext set as the view model. And there is a datagrid in the form whose itemsource should be set to TestLists. I tried the following but it doesnt work:

<DataGrid Name="dgList" ItemsSource="{Binding Systemlst.SubSystemList.TestLists}" Grid.Row="0" Margin="0,0,0,0"
                      CanUserAddRows="False" AutoGenerateColumns="False" IsReadOnly="True" >

How can I achieve this?

Your ViewModel should be a simple class of access type as public. The view model should have the ObservableCollection SubSystemList which will act as the ItemSource.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM