简体   繁体   中英

wpf cascaded combobox in Datagrid with MVVM

I am looking for binding few cascaded combobox in a WPF GridView:

Following is my requirement:

I want to develop a grid view of persons records, which would hold their Name, state name and then City name. And of-course, City combobox data would depend on the State selected.

The data grid item source would be an ObservableCollection, the Person class would look like this:

class Person
{
    name string;
    state string;
    city string;
}

And View Model for the Datagrid Window would look like this:

class DatagridWindowViewModel
{
    ObservableCollection<Person> PersonsList {get; set;}
}

And I don't want to keep the State and City lists in this class. And on changing State I should get Cities combobox populated properly from the enum.

I have enums for State and City.

1 enum for States which would have state names (say n states). Then I have n no. of Cities enums

What could be the best way of doing it so that I can avoid keeping lists in the Person class following MVVM (ie I don't want to have any code behind).

I am new to SO, please let me know if my question is not clear or I am not able to ask the question in a correct way.

在VM中保留城市和州的ID,将组合绑定到将从枚举生成的名称-值对列表,然后将其选择的值设置为Person的城市ID /州ID。

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