9

このスタイルをすべてのラベルに使用しています

    <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>

と私のサンプルラベル

<Label Grid.Column="0" Grid.Row="0" Content="Photo" Style="{StaticResource LabelStyle}" Tag="{Binding fieldsCode.firstName, UpdateSourceTrigger=PropertyChanged}"/>

しかし、TemplateBiding はプロパティの更新をサポートしていないように感じます。この問題を解決するにはどうすればよいですか

4

2 に答える 2

28

双方向バインディングのためにこれを試してください

Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Tag, Mode=TwoWay}"
于 2010-05-12T11:43:35.620 に答える
1

ControlTemplate 内からそのテンプレート化された親のプロパティへの一方向バインディングが必要な場合は、{TemplateBinding} を使用します。他のすべてのシナリオでは、代わりに {Binding} を使用します。

<TextBox Loaded="MyTextBlock_Loaded" x:Name="EditControl" Visibility="Collapsed" Text="{Binding Tag, Mode=TwoWay}" />

于 2010-05-12T11:01:33.173 に答える