Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows应用商店应用程序-两个元素一个对象绑定_C#_Xaml_Binding_Windows Store Apps - Fatal编程技术网

C# Windows应用商店应用程序-两个元素一个对象绑定

C# Windows应用商店应用程序-两个元素一个对象绑定,c#,xaml,binding,windows-store-apps,C#,Xaml,Binding,Windows Store Apps,最好的方法是什么,下面我将描述什么 我有两个文本框,在同一对象和同一属性上具有双向绑定。 现在,当我更新一个文本框中的文本时,我希望另一个文本框再次从对象中获取相同的值。这是可能的,或者我必须手动完成。例如,我可以使用TextChanged事件并设置此值。是的,您可以将单个属性绑定到两个控件 如果该类是您的DataContext(viewmodel) 在XAML中 <UserControl x:Class="WpfApplication1.MainWindow" xmlns="ht

最好的方法是什么,下面我将描述什么

我有两个文本框,在同一对象和同一属性上具有双向绑定。
现在,当我更新一个文本框中的文本时,我希望另一个文本框再次从对象中获取相同的值。这是可能的,或者我必须手动完成。例如,我可以使用TextChanged事件并设置此值。

是的,您可以将单个属性绑定到两个控件

如果该类是您的
DataContext
(viewmodel)

在XAML中

<UserControl x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="350" Width="525"
    xmlns:ViewModel="clr-namespace:WpfApplication1">
 <UserControl.DataContext>
    <ViewModel:Class1/>
 </UserControl.DataContext>
<Grid>
    <TextBox Width="150" Height="50" Text="{Binding text1, Mode=TwoWay}"/>
    <TextBox Text="{Binding text1, Mode=TwoWay}" Margin="0,232,0,0"/>
</Grid>
</UserControl>

是的,我知道。这是误解。在你们的例子中,当你们更新第一个文本框的值时,第二个文本框会自动更新他的值。没有c#。如果这是可能的话。
<UserControl x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="350" Width="525"
    xmlns:ViewModel="clr-namespace:WpfApplication1">
 <UserControl.DataContext>
    <ViewModel:Class1/>
 </UserControl.DataContext>
<Grid>
    <TextBox Width="150" Height="50" Text="{Binding text1, Mode=TwoWay}"/>
    <TextBox Text="{Binding text1, Mode=TwoWay}" Margin="0,232,0,0"/>
</Grid>
</UserControl>