Pol*_*ris 8 data-binding wpf templatebinding
我将这种风格用于所有标签
<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>
Run Code Online (Sandbox Code Playgroud)
和我的样品标签
<Label Grid.Column="0" Grid.Row="0" Content="Photo" Style="{StaticResource LabelStyle}" Tag="{Binding fieldsCode.firstName, UpdateSourceTrigger=PropertyChanged}"/>
Run Code Online (Sandbox Code Playgroud)
但我觉得TemplateBiding不支持更新属性.怎么能解决这个问题
Ams*_*nna 27
试试这个双向绑定
Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Tag, Mode=TwoWay}"
Run Code Online (Sandbox Code Playgroud)
如果您希望从 ControlTemplate 内部到其模板化父级的属性进行单向绑定,请使用 {TemplateBinding}。对于所有其他场景,请改用 {Binding}:
<TextBox Loaded="MyTextBlock_Loaded" x:Name="EditControl" Visibility="Collapsed" Text="{Binding Tag, Mode=TwoWay}" />