I’m using WPF’s regular DataGrid inside a custom control.
One of the DataGrid’s cell template content should be bound to a the Text of a Textblock or to a DependencyProperty on the custom control. (If I could bind it to any of them it’s good enough for me)
I tried to do the following binding with the ElementName but it didn’t work. I keep getting an DependencyProperty.UnsetValue –
<DataGridTemplateColumn Header="Test">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ContentPresenter>
<ContentPresenter.Content>
<MultiBinding Converter="{StaticResource TextToSpecialTextblockConverter}">
<Binding Path="SomeTextOnTheViewModel"/>
<Binding ElementName="SearchBox" Path="Text" Mode="OneWay"/>
</MultiBinding>
</ContentPresenter.Content>
</ContentPresenter>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Binding to a DependencyProperty also doesn’t work.
<DataGridTemplateColumn Header="Test">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ContentPresenter>
<ContentPresenter.Content>
<MultiBinding Converter="{StaticResource TextToSpecialTextblockConverter}">
<Binding Path="SomeTextOnTheViewModel"/>
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path="SomeDP" />
</MultiBinding>
</ContentPresenter.Content>
</ContentPresenter>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
I hope someone could help me out!
Thanks!
If the property
Propertyis defined on a view model set on theDataContextof the control orDataGridthen this sample works:Resources:
DataGrid
The DependencyProperty change notification could update the view model.
For example:
In order to bind to a dependency property
Testusing a template binding use thisWhere CustomControl1 is