I would like to add a ComboBox
to a DataGrid
or ListView
but the Combobox\'s underlying ViewSource
would be filtered by data
I would do something like this
View:
ViewModel:
public class MainWindowViewModel
{
public MainWindowViewModel()
{
SelectedItemChangedCommand = new DelegateCommand
Model:
public class Company
{
public string CompanyName { get; set; }
public List CompanyPhoneNumbers { get; set; }
}
I used Prism framework in this example. The i
and ie
are shortcuts to namespaces:
xmlns:i="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:ie="http://schemas.microsoft.com/expression/2010/interactivity"
What happens here is that the viewModel holds a list of the selected company phone numbers. Whenever the company gets changed (a different row in the grid get's selected in this example) the selected company's phone numbers is changed accordingly.
Here are some good links on MVVM:
http://www.codeproject.com/Articles/165368/WPF-MVVM-Quick-Start-Tutorial
http://www.codeproject.com/Articles/126249/MVVM-Pattern-in-WPF-A-Simple-Tutorial-for-Absolute
http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
Good luck