0

我有一个带有文本框(绑定文本框文本)的 MainPage.xaml 和一些嵌套的用户控件,它们都有一个带有模板绑定/绑定的文本框(4 个文本框)。
当我在某处更改文本时,我希望每个框中都有相同的文本。

解决方法:链接

我该怎么做才能同步所有文本?

谢谢!

MainPage.xaml(TextBoxText 是一个,我喜欢在任何地方显示)

<myContDll:DefaultContainerTemplate Caption="NewCaption">
    <StackPanel x:Name="myStackPanel">
        <sdk:Label Content="Binding TextBoxText of MainPage"/>
        <TextBox Text="{Binding TextBoxText}"/>
        <myDll:MyButtonControl x:Name="ButtonControl" Count="44"
                           Button3Caption="NewButton3" 
                           Button3Visibility="Visible"  
                           DisplayText="Form2Text2"
                           TextBoxText="{Binding TextBoxText}"/>
    </StackPanel>
</myContDll:DefaultContainerTemplate>

通用的.xaml:

<Style TargetType="local:MyButtonControl">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:MyButtonControl">
                <StackPanel>
                    <sdk:Label Content="inner control test"/>
                    <sdk:Label Content="TemplateBinding TextBoxText of MyButtonControl"/>
                    <TextBox Text="{TemplateBinding TextBoxText}"/>
                    <Button Content="{TemplateBinding Button3Caption}" Visibility="{TemplateBinding Button3Visibility}" x:Name="Button3"/>
                    <local:CountDisplayControl x:Name="Control1" TextBoxText="{TemplateBinding TextBoxText}" Visibility="{TemplateBinding VisibilityText1}" Count="{TemplateBinding Count}" DisplayText="{TemplateBinding DisplayText1}"/>
                    <local:CountDisplayControl2 x:Name="Control2" TextBoxText="{TemplateBinding TextBoxText}" Visibility="{TemplateBinding VisibilityText2}" Count="{TemplateBinding Count}" DisplayText="{TemplateBinding DisplayText2}"/>
                    <local:CountDisplayUserControl TextBoxText="{TemplateBinding TextBoxText}"/>
                </StackPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
<Style TargetType="local:CountDisplayControl">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:CountDisplayControl">
                <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">
                    <StackPanel>
                        <sdk:Label Content="Control1"/>
                        <sdk:Label Content="{TemplateBinding Count}"/>
                        <sdk:Label x:Name="labelText" Content="{TemplateBinding Text}"/>
                        <sdk:Label Content="TemplateBinding TextBoxText of CountDisplayControl"/>
                        <TextBox Text="{TemplateBinding TextBoxText}"/>
                    </StackPanel>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
<Style TargetType="local:CountDisplayControl2">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:CountDisplayControl2">
                <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">
                    <StackPanel>
                        <sdk:Label Content="Control2"/>
                        <sdk:Label Content="{TemplateBinding Count}"/>
                        <sdk:Label x:Name="labelText" Content="{TemplateBinding Text}"/>
                        <sdk:Label Content="TemplateBinding TextBoxText of CountDisplayControl2"/>
                        <TextBox Text="{TemplateBinding TextBoxText}"/>
                    </StackPanel>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
4

1 回答 1

0

尝试设置你Binding ModeTwoWay绑定:

<myContDll:DefaultContainerTemplate Caption="NewCaption">
    <StackPanel x:Name="myStackPanel">
        <sdk:Label Content="Binding TextBoxText of MainPage"/>
        <TextBox Text="{Binding TextBoxText, Mode=TwoWay}"/>
        <myDll:MyButtonControl x:Name="ButtonControl" Count="44"
                    Button3Caption="NewButton3" 
                    Button3Visibility="Visible"  
                    DisplayText="Form2Text2"
                    TextBoxText="{Binding TextBoxText, Mode=TwoWay}"/>
    </StackPanel>
</myContDll:DefaultContainerTemplate>
于 2012-07-03T14:49:43.533 回答