0
我有一個帶有TextBox(Binding TextBoxText)的MainPage.xaml和一些嵌套的UserControls,它們都帶有一個帶有TemplateBinding/Binding的TextBox(4 TextBoxes)。
我想在每個框中都有相同的文本,當我在某處更改文本時。Silverlight,通過UserControls的TemplateBindings的路徑
解決辦法:Link
我能做什麼來同步所有文本?
謝謝!
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>
Generic.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>
嗨!謝謝!我試過這個,並更改(/上傳)我的解決方案。不幸的是,它不起作用......我想,我需要源定義...但我的測試錯過了...... – user1453898