我想在我创建的用户控件上设置双向绑定。用户控件双向绑定
当我使用在XAML的控制被设置在DataContext像这样...
<uc:MyUserControl DataContext="{Binding Path=MyObject, Mode=TwoWay}" />
我的用户控制被定义为以下....
<UserControl x:Class="SilverlightApplication1.XText"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<TextBox x:Name="Text" Text="{Binding}"/>
</Grid>
</UserControl>
显示数据正确的,但是,如果我让我改变,我希望它用TwoWay绑定更新。
我已经在下面试过了,但是它在运行时出错,因为没有定义路径。
<Grid x:Name="LayoutRoot" Background="White">
<TextBox x:Name="Text" Text="{Binding Mode=TwoWay}"/>
</Grid>
</UserControl>
如何获得用户控件内部的控制,以双向绑定到DataContext任何想法?
MyText.SetBinding()块仍然有点黑客。我认为你会发现使用它比它的价值更多的问题。 – Doug 2010-08-24 15:43:30