locked
Is there a way to determine the dominate baseline in the UI Controls?

    Question

  • For example, how would I determine the baseline location for the text contained in a standard button? I'm looking to wire-up a layout library.

    Thanks for any assistance,

    Sean

    Thursday, May 3, 2012 5:07 PM

All replies

  • Hello,

    Did you try the padding properties, like this
    Padding="10,10,10,0"
    You can check the Padding in this document
    http://msdn.microsoft.com/en-us/library/ms751709.aspx

    If you want to more closer to bottom, you can try the TextBox with  VerticalAlignment="Stretch"

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Jesse Jiang Friday, May 18, 2012 6:52 AM
    • Unmarked as answer by Sean Parent Thursday, May 31, 2012 9:50 PM
    Friday, May 4, 2012 9:26 AM
  • Hi Sean,

    There is no property provided to determine this. Since a custom template could be provided the text could be anywhere. Even with the default template, the ContentPresenter can take an arbitrary element and doesn't have to be text (or simple text).

            <Button Click="Button_Click_1">
            <StackPanel>
                <Rectangle Width="50" Height="5" Fill="Red"></Rectangle>
                <TextBlock>Text Line 1</TextBlock>
                <TextBlock>Text Line 2</TextBlock>
                <TextBlock>Text Line 3</TextBlock>
                <Rectangle Width="50" Height="5" Fill="Red"></Rectangle>
            </StackPanel>    
            </Button>

    --Rob

    • Marked as answer by Jesse Jiang Friday, May 18, 2012 6:52 AM
    • Unmarked as answer by Sean Parent Thursday, May 31, 2012 9:50 PM
    Saturday, May 5, 2012 12:44 AM
    Owner
  • Of course the sizes of all contained elements still must be calculated to determine the ideal size for the element - if there is no text within the element then returning a value of none for dominate baseline would be acceptable. If there is text within the element then there is a dominate baseline. Baseline alignment is important to proper UI layout, I'd I'd rather not have to build tables and do this by hand.

    Let me put this a different way - If I'm constructing a UI element from code (say a button or checkbox) so I have complete control over the styling, how would I determine the dominate baseline? I can't even find a baseline property for a text element. I don't mind having to walk the button structure - but I can't figure out a way to find the baseline at all.

    Ideally in your example above I'd like to be able to get a list of baselines for all of the text blocks. and I'd like to be able to adjust those so I could align them to a set of controls placed to the right (or left) of that button.

    Sean

    Friday, May 25, 2012 7:33 PM