我有一个MainWindow,并在其中包含UserControl1和UserControl2,它们都包含一个TextBox。如何在不同的用户控件中绑定文本框
什么是绑定这两个文本框的Text属性的最佳方式。
MainWindow.xaml
<Window x:Class="DataBindTest1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:DataBindTest1">
<StackPanel>
<Controls:UserControl1/>
<Controls:UserControl2/>
</StackPanel>
</Window>
UserControl1.xaml
<UserControl x:Class="DataBindTest1.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<TextBox Name="uc1TextBox">ExampleText</TextBox>
</Grid>
</UserControl>
UserControl2.xaml
<UserControl x:Class="DataBindTest1.UserControl2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<TextBox Name="uc2TextBox" /> <!--I want this to be bound to the Text property of uc1TextBox (which is in UserControl1)-->
</Grid>
</UserControl>
提前任何帮助谢谢,
维杰
我改变UserControl2.xaml此,而是它没有工作:“<用户控件X:类= “DataBindTest1.UserControl2” 的xmlns =“HTTP://schemas.mic rosoft.com/winfx/2006/xaml/presentation” 的xmlns:X = “http://schemas.microsoft.com/winfx/2006/xaml” 的xmlns:控制= “CLR-名称空间:DataBindTest1”> UserControl> ' –
vijay