I have a custom dependency property that I would like to bind to and pass into a value converter within a style. Here is the code:
<Window.Resources>
<local:Conv x:Key="MyConv" />
<Style x:Key="TextBoxField" TargetType="{x:Type TextBox}">
<Setter Property="DataContext">
<Setter.Value>
<MultiBinding Converter="{StaticResource MyConv}">
<Binding RelativeSource="{RelativeSource AncestorType={x:Type Window}}" />
<Binding Path="local:FieldName.FieldId" RelativeSource="{RelativeSource AncestorType={x:Type TextBox}}" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<TextBox local:FieldName.FieldId="FirstName" Style="{StaticResource TextBoxField}"/>
</Grid>
I have set my custom dependency property FieldId on the TextBox. In the style, I am trying to reference it to pass into my converter. The Window passes in correctly, but FieldId comes in as an Unset value.
I have tried various RelativeSource's, referencing "local" or not "local" while referencing the custom property, etc.
FieldName.FieldIdappears to be an attached property, which must be put in parentheses in a Binding Path, i.e.Path="(local:FieldName.FieldId)". See PropertyPath for Objects in Data Binding.