tags:

views:

92

answers:

3

I'd like to know if it is possible to define as the text of a Button in WPF, something like: a b c

I've tried setting alt text

but that doesn't seem to work.

Is it only possible to use the Bold tag with FlowDocuments?

Thanks

+1  A: 

Try <Button><TextBlock>a<Bold>b</Bold>c</TextBlock></Button>.

SLaks
You were right. It works now.
SLaks
+1  A: 

This will work.

<Grid>
   <Button Name="button1" Width="40" Height="40" 
           Content="something" FontWeight="Bold" />
</Grid>
Steve Danner
That's not what I asked for..
devoured elysium
Ah, I see you only want some bold text and not all of it...
Steve Danner
+4  A: 

Use a TextBlock to hold the formatted text:

<Button>
  <TextBlock>Hey <Bold>you</Bold>!!!</TextBlock>
</Button>

Per your comment, if you want to be explicit about the fact that this sets the Content property, you can use XAML property element syntax to do so:

<Button>
  <Button.Content>
    <TextBlock>Hey <Bold>you</Bold>!!!</TextBlock>
  </Button.Content>
</Button>

However this is redundant because Button has a ContentPropertyAttribute which makes the first version exactly equivalent to the second anyway.

itowlson
Perfect! That'll do the job. Now, is any way to put it inside Contents? Not that I need it, just trying to understand what is going on here.
devoured elysium
No. An attribute can only hold plain text.
SLaks
The only way to do what you want is as posted. When you use the Content property, its the same as setting the text in the old WinForms.
Rob Allen
Yes, but only using XAML property element syntax. I've updated the answer to show how, but to reiterate, it's redundant to do so: a child element of a Button automatically becomes its Content anyway.
itowlson