(X) Hide this
    • Login
    • Join
      • Say No Bots Generate New Image
        By clicking 'Register' you accept the terms of use .
        Login with Facebook

Tip: How to set the text of a Button?

(1 votes)
Denislav Savkov
>
Denislav Savkov
Joined Feb 11, 2008
Articles:   14
Comments:   6
More Articles
0 comments   /   posted on Sep 04, 2008
Tags:   button , denislav-savkov
Categories:   Controls

In Silverlight the Button, as some other controls does not have the old well known Text property. It is replaced by a new property named Content of type object. The idea is to remove the limitation to show only strings as content of a control. Now with this new approach you can put whatever you wish inside of a Button. This makes the presentation layer extremely powerful. However if you provide a regular string for the Content then the result will be exactly as if we used the Text property.

Xaml

<Button x:Name="simpleButton" Content="Click Me" />
<Button x:Name="advancedButton">
    <Button.Content>
        <CheckBox Content="Check box on a button"></CheckBox>
    </Button.Content>
</Button>

C#

Button simpleButton = new Button();
simpleButton.Content = "Click Me";
 
Button advancedButton = new Button();
CheckBox checkBox = new CheckBox();
checkBox.Content = "Check box on a button";
advancedButton.Content = checkBox;

As you can see the first button named simpleButton uses plain text 'Click Me' for its content, while the second button named advancedButton hosts check box control with the text 'Check box on a button'.

That's it!

 


Subscribe

Comments

No comments

Add Comment

Login to comment:
  *      *       
Login with Facebook