Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I am developing an universal Windows 8.1 App, primary for Windows Phone 8.1. There are different screen sizes and resolutions of Windows Phone 8.1 smartphones, so I am scaling the controls (TextBoxes, Images, Buttons etc.) automatically by using Grids. This works great!

I am using XALM without Silverlight!

However, I have a problem with TextBoxes:
How shall I vertically center the text in a TextBox?
I can not use top-padding because the height of my TextBox depends on the screen resolution of the smartphone.

"VerticalContentAlignment" does not work in this case!

The style
XML
<scrollviewer ...="" verticalalignment="Center" />

as a custom control template does not work, too.

Thanks for any advices!

Best wishes,
Miroslav Stimac
Posted
Updated 21-Aug-15 9:54am
v2
Comments
Sergey Alexandrovich Kryukov 21-Aug-15 16:25pm    
There are no such elements and attributes as "scrollviewer" and "verticalalignment"; everything is case-sensitive. Why scroll viewer? how is it related to alignment of text.
The text is aligned vertically by default, unless you use uneven padding on purpose. Maybe you just want dynamic padding, depending on screen size?
—SA
Afzaal Ahmad Zeeshan 21-Aug-15 16:29pm    
Then just don't, TextBoxes are meant to be used for getting the input. If user inputs everything only in one line, let him. There is no need for the text to be in center; otherwise you will end up ruining entire UX. The alignment is already done, underground, so that you just have to create a control and everything else will be handled by the OS.

Plus, follow Sergey's comment and keep everything case-sensitive otherwise application won't compile.

1 solution

Please see my comment to the question. So, maybe all you need is to use Padding with Thickness in device-independent units. Please see: https://msdn.microsoft.com/en-us/library/system.windows.controls.textblock.padding%28v=vs.110%29.aspx[^].

For some background on device-independent pixels, please see: https://msdn.microsoft.com/en-us/library/windows/desktop/ff684173%28v=vs.85%29.aspx[^].

Please let me know if your problem is different.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900