Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.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# 使用Dependency属性根据WPF中另一个TextBock的值更新TextBlock的值_C#_.net_Wpf - Fatal编程技术网

C# 使用Dependency属性根据WPF中另一个TextBock的值更新TextBlock的值

C# 使用Dependency属性根据WPF中另一个TextBock的值更新TextBlock的值,c#,.net,wpf,C#,.net,Wpf,在我的XAML中,我有以下两个文本块 <TextBlock Name="tbGeneratedSignature" TextWrapping="Wrap" Margin="2,2,0,0" Height="auto" Width="390" Foreground="Black" TextDecorations="None" VerticalAlignment="Top" Focusable="False"/> <TextBlock Name="tbSignatureTe

在我的XAML中,我有以下两个文本块

 <TextBlock Name="tbGeneratedSignature" TextWrapping="Wrap" Margin="2,2,0,0" Height="auto" Width="390"  Foreground="Black" TextDecorations="None" VerticalAlignment="Top" Focusable="False"/>


<TextBlock Name="tbSignatureText" TextWrapping="Wrap" Margin="5" Height="auto" Width="440" Foreground="Black"  />


基于tbGeneratedSignature.Text我想只使用XAML而不是使用C#为tbSignatureText.Text指定相同的值。

您考虑过绑定吗

<TextBlock Name="tbSignatureText" 
           Text="{Binding ElementName=tbGeneratedSignature, Path=Text, UpdateSourceTrigger=PropertyChanged}" 
           TextWrapping="Wrap" 
           Margin="5" 
           Height="auto" 
           Width="440" 
           Foreground="Black"  />



感谢您提供了简单高效的方法,即使我没有编写UpdateSourceTrigger=PropertyChangedYea,我也不确定
TextBlock
的默认绑定是
UpdateSourceTrigger=PropertyChanged
还是
LostFocus
。当您绑定到
TextBox
Text
属性时,它默认为
UpdateSourceTrigger=LostFocus
,因此您必须将其更改为
PropertyChanged
<TextBlock Name="tbGeneratedSignature" TextWrapping="Wrap" Margin="2,2,0,0" Height="auto" Width="390"  Foreground="Black" TextDecorations="None" VerticalAlignment="Top" Focusable="False"/>


<TextBlock Name="tbSignatureText" Text="{Binding ElementName=tbGeneratedSignature, Path=Text}" TextWrapping="Wrap" Margin="5" Height="auto" Width="440" Foreground="Black"  />