This question is locked. New answers and comments are not allowed.
Hi
I am trying to bind a GridViewComboBoxColumn to a property in my ViewModel.
For example:
A view "HomeView" with DataContext "HomeViewModel"
"HomeViewModel" has an observable collection "Tasks". Each task has a property "TypeId".
"HomeViewModel" has an observable collection "Types".
The GridView has ItemsSource="{Binding Path=Tasks}"
The GridView has a GridViewComboBoxColumn that should list all "Types".
If I use ItemsSource="{Binding Path=Types}" for the column, the column will be blank until focused.
When I click on the column, the values appear. When the column looses focus, the entire column is blank.
If I use ItemsSourceBinding="{Binding Path=Types}" for the column, the binding will search for a property "Types" in the "Task"
I have tried binding to "ElementName", and "Path=DataContext.Types", where ElementName refers to the View, but this did not work.
I have found these solutions to be working, but both might be a problem if I am using d:DataContext for designtime support:
ItemsSourceBinding="{Binding Path=FindShared[HomeViewModel].Types, Source={StaticResource VMLocator}}"
(http://johnpapa.net/silverlight/simple-viewmodel-locator-for-mvvm-the-patients-have-left-the-asylum/)
Each call to "FindShared" will result in 6 bindings, and will be a performance problem.
This seems to be a better solution:
ItemsSourceBinding="{Binding Path=DataSource.Types, Source={StaticResource DataContextProxy}}"
http://weblogs.asp.net/dwahlin/archive/2009/08/20/creating-a-silverlight-datacontext-proxy-to-simplify-data-binding-in-nested-controls.aspx
Do you have other better solutions for binding a ViewModel property to the ItemsSource in the GridViewComboBoxColumn?
regards
JS
I am trying to bind a GridViewComboBoxColumn to a property in my ViewModel.
For example:
A view "HomeView" with DataContext "HomeViewModel"
"HomeViewModel" has an observable collection "Tasks". Each task has a property "TypeId".
"HomeViewModel" has an observable collection "Types".
The GridView has ItemsSource="{Binding Path=Tasks}"
The GridView has a GridViewComboBoxColumn that should list all "Types".
If I use ItemsSource="{Binding Path=Types}" for the column, the column will be blank until focused.
When I click on the column, the values appear. When the column looses focus, the entire column is blank.
If I use ItemsSourceBinding="{Binding Path=Types}" for the column, the binding will search for a property "Types" in the "Task"
I have tried binding to "ElementName", and "Path=DataContext.Types", where ElementName refers to the View, but this did not work.
I have found these solutions to be working, but both might be a problem if I am using d:DataContext for designtime support:
ItemsSourceBinding="{Binding Path=FindShared[HomeViewModel].Types, Source={StaticResource VMLocator}}"
(http://johnpapa.net/silverlight/simple-viewmodel-locator-for-mvvm-the-patients-have-left-the-asylum/)
Each call to "FindShared" will result in 6 bindings, and will be a performance problem.
This seems to be a better solution:
ItemsSourceBinding="{Binding Path=DataSource.Types, Source={StaticResource DataContextProxy}}"
http://weblogs.asp.net/dwahlin/archive/2009/08/20/creating-a-silverlight-datacontext-proxy-to-simplify-data-binding-in-nested-controls.aspx
Do you have other better solutions for binding a ViewModel property to the ItemsSource in the GridViewComboBoxColumn?
regards
JS