Binding to ViewModel from XAML
I am new to the MVVM model, so I would like some advice, the solution I'm using right now does not seem to work.
Description: I have a Viewmodel containing an observablecollection of Customers, I display these in a grid with "Back" and "Forward" buttons. The grids datacontext is set to the SelectedCustomer which is a property in my viewmodel.
So far so good...
However, the customers have a statusfield, which is the integer of the statusrow in the database. In my viewmodel I have this list (observablecollection) populated, but when I try to populate a combobox in the CustomerGrid there is no data displayed. I guess this is because the Datacontext on the grid is the SelectedCustomer property, and the statuslist is in the root viewmodel开发者_开发知识库.
The Question is this, how can my combobox access my statuslist from within the customergrid, or how should I tackle this situation?
{Binding DataContext.ListOfStatus, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TypeOfParentControl}}}
You can bind to parent's data context
some grids allow binding of combobox columns too. That depends on the grid - I never used a grid in WPF or Silverlight so take it just as a hint.
精彩评论