Binding String Property in Code-Behind TextBlock

前端 未结 1 1749
时光取名叫无心
时光取名叫无心 2020-12-01 16:13

i am trying to binding a very simple property to a TextBlock, but I have to do all in code-behind (C#).

What i am trying to do is:

public string Some         


        
相关标签:
1条回答
  • 2020-12-01 16:32

    Use BindingOperations

    Binding binding = new Binding();
    binding.Path = new PropertyPath("SomeText");
    binding.Source = sourceObject;  // view model?
    
    BindingOperations.SetBinding(theTextBlock, TextBlock.TextProperty, binding);
    
    0 讨论(0)
提交回复
热议问题