2

次のテキストボックスがあり、スタイルを追加するまでバインディングは正常に機能しています。

<TextBox Text="{Binding SelectedGroupPolicyTermSummary.ImportantInfo, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
         HorizontalAlignment="Stretch"  AcceptsReturn="True" 
         IsReadOnly="{Binding IsEditable, Converter={StaticResource InvertedBoolConverter}}"
         Foreground="Red" TextWrapping="Wrap">
    <TextBox.Style>
        <Style TargetType="{x:Type TextBox}">
            <Style.Triggers>
                <Trigger Property="TextBox.IsReadOnly" Value="True">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type TextBox}">
                                <TextBox Text="{TemplateBinding Text}" 
                                         VerticalAlignment="Bottom" 
                                         HorizontalAlignment="{TemplateBinding HorizontalAlignment}"                     
                                         Style="{DynamicResource SelectableTextStyle}" 
                                         TextWrapping="{TemplateBinding TextWrapping}" 
                                         Foreground="{TemplateBinding Foreground}"
                                         Width="{TemplateBinding Width}"/>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                    <Setter Property="Width" Value="Auto"/>
                </Trigger>
                <Trigger Property="TextBox.IsReadOnly" Value="False">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type TextBox}" >
                                <TextBox Text="{TemplateBinding Text}" 
                                         VerticalAlignment="Bottom" 
                                         HorizontalAlignment="{TemplateBinding HorizontalAlignment}"                     
                                         Style="{DynamicResource TextBoxStyle}" 
                                         TextWrapping="{TemplateBinding TextWrapping}" 
                                         Foreground="{TemplateBinding Foreground}"
                                         Width="{TemplateBinding Width}" 
                                         AcceptsReturn="{TemplateBinding AcceptsReturn}">
                                </TextBox>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
    </TextBox.Style>
</TextBox>

スタイルを適用した後、テキストボックスにデータが入力されますが、変更はコードに返されません。なぜ何かアイデアはありますか?

4

2 に答える 2

1

コントロールテンプレートでバインディングを双方向に設定してみましたか?

Binding NameOfProperty, Mode=TwoWay
于 2012-06-21T16:30:19.850 に答える
1

TemplateBindingマークアップ拡張機能は、基本的に次のバインディングを提供します。

{Binding RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}

背景色などについては、問題なく機能します。ただし、テキストのようなものを最後までバインドしたい場合は、ロングハンドを使用してモードを変更する必要があります。

Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
于 2012-06-21T16:35:06.267 に答える