上一篇文章中在XAML中通过标识扩展实现了一个简单的数据绑定,这篇中将通过C#代码实现上篇相同效果。

上面说过,上篇是通过扩展标识实现TextBlock的数据绑定:

  代码


        
<TextBlock x:Name="LastActivityAmountValueTextBlock"
            Grid.Row
="14"
            Grid.Column
="1"
            Margin
="2"
            Text
="{Binding LastActivityAmount}" >
        
</TextBlock>

 

 这篇中将通过C#代码实现,扩展标识绑定自然不再需要了

 


        
<TextBlock x:Name="LastActivityAmountValueTextBlock"
            Grid.Row
="14"
            Grid.Column
="1"
            Margin
="2"
        </TextBlock
>

 

 

  C#代码中实现如下:


       LastActivityAmountValueTextBlock.SetBinding(TextBlock.TextProperty, 
new Binding("LastActivityAmount"));

 

 

 

 

相关文章:

  • 2022-12-23
  • 2021-06-07
  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
  • 2021-12-16
  • 2021-07-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
  • 2021-07-17
相关资源
相似解决方案