How to add text to a WPF Label in code?

前端 未结 6 551
耶瑟儿~
耶瑟儿~ 2020-12-02 16:32

I feel stupid but cannot find out how to add a text to a WPF Label control in code. Like following for a TextBlock:

DesrTextBlock.Text = \"some text\";


        
相关标签:
6条回答
  • 2020-12-02 16:43

    In normal winForms, value of Label object is changed by,

    myLabel.Text= "Your desired string";
    

    But in WPF Label control, you have to use .content property of Label control for example,

    myLabel.Content= "Your desired string";
    
    0 讨论(0)
  • 2020-12-02 16:43

    Label myLabel = new Label (); myLabel.Content = "Hello World!";

    0 讨论(0)
  • 2020-12-02 16:48

    You can use the Content property on pretty much all visual WPF controls to access the stuff inside them. There's a heirarchy of classes that the controls belong to, and any descendants of ContentControl will work in this way.

    0 讨论(0)
  • 2020-12-02 16:53

    I believe you want to set the Content property. This has more information on what is available to a label.

    0 讨论(0)
  • 2020-12-02 17:00

    you can use TextBlock control and assign the text property.

    0 讨论(0)
  • 2020-12-02 17:03

    Try DesrLabel.Content. Its the WPF way.

    0 讨论(0)
提交回复
热议问题