silverlight - Bind to the page datacontext from a combo box in a data grid -
I have a page with a visual model. I am setting the binding source of the combo box for the visual model from the templated DataGrid column. It gives me a blank reference error.
This is my XML:
& lt; Navigation: Page. Resources & gt; & Lt; Vm: SiteViewModel x: Key = "ViewModel" /> & Lt; / Navigation: Page.Resources & gt; & Lt; Navigation: Page.DataContext & gt; & Lt; Binding source = "{static resource view model}" /> & Lt; / Navigation: Page.DataContext & gt;
...
& lt; Data: Datagrid itemsource = "{binding current site. Contact}" & gt; & Lt; Data: DataGrid.Columns & gt; & Lt; Data: DataGrade Template column header = "role" & gt; & Lt; Data: DataGridTemplateColumn.CellTemplate & gt; & Lt; DataTemplate & gt; & Lt; Combo box itemsource = "{binding path = roles, source = ???}}" & gt; & Lt; ComboBox.ItemTemplate & gt; & Lt; DataTemplate & gt; & Lt; StackPanel Orientation = "Horizontal" & gt; & Lt; Text block text = "{binding path = role name}" vertical alignment = "center" /> & Lt; / StackPanel & gt; & Lt; / DataTemplate & gt; & Lt; /ComboBox.ItemTemplate> & Lt; / ComboBox & gt; & Lt; / DataTemplate & gt; & Lt; / Data: DataGridTemplateColumn.CellTemplate & gt; & Lt; / Data: DataGridTemplateColumn & gt; & Lt; / Data: DataGrid.Columns & gt; & Lt; / Data: Data grid & gt;
First you can simplify your xaml:
< Pre> & lt; Navigation: Page.DataContex & gt; & Lt; Vm: SiteViewModel / & gt; & Lt; / Navigation: Page.DataContext & gt;
The second thing is that once you get inside the datagrid that has a different datacentext, you can not access the page's datacentext. To go around it, I suggest that it is easy to get out of it. Using it you can add:
& lt; Navigation: Page. Datacontex & gt; & Lt; Vm: SiteViewModel / & gt; & Lt; / Navigation: Page.DataContext & gt; & Lt; Navigation: Page.Resources & gt; & Lt; Control: DatacontexProxix X: Key = "DatacontextProxy" /> & Lt; / Navigation: Page.Resources & gt;
...
& lt; Data: Datagrid itemsource = "{binding current site. Contact}" & gt; & Lt; Data: DataGrid.Columns & gt; & Lt; Data: DataGrade Template column header = "role" & gt; & Lt; Data: DataGridTemplateColumn.CellTemplate & gt; & Lt; DataTemplate & gt; & Lt; Combo box itemsource = "{binding source = {static resource datacontaxprocess}, path = data processing.rolis}" & gt; ... & lt; / Combo box & gt; & Lt; / DataTemplate & gt; & Lt; / Data: DataGridTemplateColumn.CellTemplate & gt; & Lt; / Data: DataGridTemplateColumn & gt; & Lt; / Data: DataGrid.Columns & gt; & Lt; / Data: Data grid & gt;
Comments
Post a Comment