Is there a way to determine the dominate baseline in the UI Controls?
-
03 Mayıs 2012 Perşembe 17:07
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
Tüm Yanıtlar
-
04 Mayıs 2012 Cuma 09:26Moderatör
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.aspxIf you want to more closer to bottom, you can try the TextBox with VerticalAlignment="Stretch"
Best regards,
JesseJesse Jiang [MSFT]
MSDN Community Support | Feedback to us
- Yanıt Olarak İşaretleyen Jesse JiangMicrosoft Contingent Staff, Moderator 18 Mayıs 2012 Cuma 06:52
- Yanıt İşaretini Geri Alan Sean Parent 31 Mayıs 2012 Perşembe 21:50
-
05 Mayıs 2012 Cumartesi 00:44Moderatör
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
- Yanıt Olarak İşaretleyen Jesse JiangMicrosoft Contingent Staff, Moderator 18 Mayıs 2012 Cuma 06:52
- Yanıt İşaretini Geri Alan Sean Parent 31 Mayıs 2012 Perşembe 21:50
-
25 Mayıs 2012 Cuma 19:33
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