3 Replies - 2014 Views - Last Post: 31 October 2011 - 08:43 AM Rate Topic: -----

#1 MishaSharp   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 31-October 11

how to write some lines in a button? (WPF)

Posted 31 October 2011 - 03:28 AM

I know that if I write a text then i can make \n and it's starting a new line.
But how can I do it in button ? (\n doesn't work there).

(some more questions):

* I want to write in the center in a textblock.
for center I write in xaml: TextAlignment = "Center"
but now I want also the text to be not in the top but also in the center... which code should I write? (If i do VerticalAlign = "Center" - it makes the textblock position to be in the center and not the text...).

* When do i use Color. in WPF? (I know that if I want to change background or foreground etc.. I write Brushes. ...).


Hope you help me, I am new in this forum and new in C# :)

Is This A Good Question/Topic? 0
  • +

Replies To: how to write some lines in a button? (WPF)

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6256
  • View blog
  • Posts: 24,025
  • Joined: 23-August 08

Re: how to write some lines in a button? (WPF)

Posted 31 October 2011 - 03:51 AM

Moved to WPF
Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1536
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: how to write some lines in a button? (WPF)

Posted 31 October 2011 - 08:05 AM

First question...how to make text in a Button span multiple lines. The text of a Button is really a Content control. It can be simply applied text, or you can get more creative and it can be a group of controls. I simply used a vertical StackPanel with two TextBlocks inside.

<Button
    Height="43"
    HorizontalAlignment="Left"
    Margin="150,234,0,0"
    Name="button1"
    VerticalAlignment="Top"
    Width="91"
    Click="button1_Click">
    <StackPanel Orientation="Vertical">
        <TextBlock
            Text="Some Text" />
        <TextBlock
            Text="More Text" />
    </StackPanel>
</Button>



Second Question...how to make a TextBlock's Text centered horizontal and vertical. By default, the TextBlock control doesn't do vertical text alignment. To get around this, put the TextBlock inside of a container control. I use a Border, with no BorderBrush, and then set the TextBlock's HorizontalAlignment and VerticalAlignment to Center.

<Border
    Height="45"
    Width="200"
    BorderBrush="{x:Null}"
    Margin="0,63,0,203">
    <TextBlock
        HorizontalAlignment="Center"
        Name="textBlock1"
        Text="TextBlock"
        VerticalAlignment="Center" />
</Border>



Third question...when to use Color. WPF doesn't use the Color class directly. It uses a number of Brush classes, like the SolidColorBrush class. For instance, if you want to set the Background color of a Button to Red, you would use this code...

button1.Background = new SolidColorBrush(Colors.Red);


Was This Post Helpful? 1
  • +
  • -

#4 MishaSharp   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 31-October 11

Re: how to write some lines in a button? (WPF)

Posted 31 October 2011 - 08:43 AM

You helped me very much.
Thank you :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1