I have a Control
(ZlsUnitBrowserActive
) with two DependencyProperties
MaxWidthIdentifier
/PropertiesDataTemplate
. I'm stuck when try to bind these two properties in the Style
:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='PlcFramework.Zls.Production.ProductionControls.ZlsUnitBrowserActive', AncestorLevel='1''. BindingExpression:Path=PropertiesDataTemplate; DataItem=null; target element is 'DataGridTemplateColumn' (HashCode=30225241); target property is 'CellTemplate' (type 'DataTemplate')
<Style TargetType="productionControls:ZlsUnitBrowserActive">
<Style.Setters>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="productionControls:ZlsUnitBrowserActive">
<DataGrid>
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate
MaxWidth="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=productionControls:ZlsUnitBrowserActive}, Path=MaxWidthIdentifier}"
CellTemplate="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=productionControls:ZlsUnitBrowserActive}, Path=PropertiesDataTemplate}"/>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
Is there a special trick? Also tried by caching the ZlsUnitBrowserActive
instance in DataGrid.Tag
(see post: https://stackoverflow.com/a/3668699/6229375), without success.