Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8496441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:51:23+00:00 2026-06-10T23:51:23+00:00

I’m struggling to get some finer layout issues working on a WPF button, essentially

  • 0

I’m struggling to get some finer layout issues working on a WPF button, essentially I’m trying to centre the text inside the button? At the moment I dynamically set several buttons in code with something similar to

        button1.Content = (option1 != 0.0)
            ? option1.ToString() + "\n"   +  "Centre"
            : string.Empty;
        button2.Content = (option2 != 0.0)
            ? option2.ToString() + "\n"   + "Quite"
            : string.Empty;
        button3.Content = (option3 != 0.0)
            ? option.ToString() + "\n" + "Not"
            : string.Empty;

and in XAML both vertical and horizontal content alignment is centre?

<Button Height="30" HorizontalAlignment="Left" Margin="254,0,0,0" Name="button1"
     VerticalAlignment="Top" Width="50" Click="button_Click" 
    HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="10"
       FontStretch="SemiCondensed"/>

but this doesn’t give me the layout I desire, (see below)

enter image description here

  1. How do get both the values on top to be centred and the text on the bottom to be centred?

  2. If I wanted the bottom text to have font size 10 bold and the top to be font size 14 normal – how do I do that?

Many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:51:25+00:00Added an answer on June 10, 2026 at 11:51 pm

    I think the easiest way is to use two Textblocks inside the Button and to setup databindings.

    <Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <StackPanel Orientation="Horizontal" TextBlock.TextAlignment="Center" >
        <Button Height="50" Width="80">
            <StackPanel>
                <TextBlock Text="{Binding Text1}" FontSize="14"  />
                <TextBlock Text="{Binding Text2}" FontSize="10"  FontWeight="Bold"/>
            </StackPanel>
        </Button>
    </StackPanel>
    

    public partial class MainWindow : Window
    {
         public string Text1 { get; set; }
        public string Text2 { get; set; }
    
        public MainWindow()
        {
            InitializeComponent();
            Text1 = "10";
            Text2 = "TEST Test";
            DataContext = this;
        }
    }
    

    please also read MVVM / INotifyPropertychanged tutorials if you don’t already know this patterns (because my example does not implement this interface, the content of the buttonts will not refresh if you change a TextX property)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.