簡體   English   中英

使用Dependency屬性基於WPF中另一個TextBock的值更新TextBlock的值

[英]Updating the value of a TextBlock on the basis of value of another TextBock in WPF using Dependency property

在我的XAML中,我有以下兩個textBlocks

 <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"  />
<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"  />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM