I use this style for all my labels
<Style TargetType="Label" x:Key="LabelStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Label">
<StackPanel Orientation="Horizontal" >
<TextBox Loaded="MyTextBlock_Loaded" x:Name="EditControl" Visibility="Collapsed" Text="{TemplateBinding Tag}" />
<Label Content="{TemplateBinding Content}" Grid.Column="1" Grid.Row="1">
</Label>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
and my sample label
<Label Grid.Column="0" Grid.Row="0" Content="Photo" Style="{StaticResource LabelStyle}" Tag="{Binding fieldsCode.firstName, UpdateSourceTrigger=PropertyChanged}"/>
But I feel that TemplateBiding doesn't support update of property. How can solve this issue
Try this for two-way binding
Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Tag, Mode=TwoWay}"
If you want a one-way binding from within the ControlTemplate to a property of its templated parent, use {TemplateBinding}. For all other scenarios use {Binding} instead:
<TextBox Loaded="MyTextBlock_Loaded" x:Name="EditControl" Visibility="Collapsed" Text="{Binding Tag, Mode=TwoWay}" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With