简体   繁体   English

Windows应用商店和TextBox的拉伸问题,响应式设计

[英]Windows store app and TextBox stretch issue, responsive design

I'm developing windows store application and I have big issue with textbox stretching. 我正在开发Windows商店应用程序,并且文本框拉伸存在很大问题。 I'd like to have responsive design that means I'm using a lot of Grids and VerticalAlignment="Stretch" and HorizontalAlignment="Stretch" 我想要响应式设计,这意味着我使用了大量的GridsVerticalAlignment="Stretch"HorizontalAlignment="Stretch"

Problem happens that FontSize in TextBoxes are the same and is not aligned to center. 发生问题,即TextBoxes中的FontSize相同且未居中对齐。 That is reason why I'm using ViewBox . 这就是为什么我使用ViewBox原因。

But ViewBox is not allowed to stretch and fill space in Grid cell. 但是不允许ViewBox拉伸和填充Grid单元中的空间。

<Viewbox Grid.Row="1" 
    Grid.Column="1" 
    HorizontalAlignment="Stretch" 
    VerticalAlignment="Stretch" >
    <TextBox HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
        Text="{Binding Name, Mode=TwoWay}" 
        HorizontalAlignment="Stretch" 
        VerticalAlignment="Stretch"/>
</Viewbox>

I could use some hardcoded sizes but in various types of the resolution makes me desperate to make my UI fitable to all types of devices. 我可以使用一些硬编码的大小,但是在各种类型的分辨率中,我迫切希望使UI适合所有类型的设备。

I also try to count sizes according to actual screen size but this approach is very cumbersome. 我也尝试根据实际屏幕尺寸计算尺寸,但是这种方法非常麻烦。

  • Do you have any idea how to solve this issue? 您有解决该问题的想法吗?
  • What is the best way to do responsive design in windows store app? 在Windows Store应用中进行响应式设计的最佳方法是什么?
  • Dont you know some 3rd party TextBox control that is better like native winRT control? 您是否不知道一些像本地winRT控件更好的第三方TextBox控件?
  • Is it good way to use ViewBox for discrete control or is better to use ViewBox for whole screen and set hardcoded sizes? 是将ViewBox用于离散控件的好方法,还是将ViewBox用于整个屏幕并设置硬编码的大小更好?

Stretching a TextBox control horizontally or vertically, doesn't lead to stretching the text inside it, this just causes that the Control resizes to fill available space and displays more text inside it. 水平或垂直拉伸TextBox控件不会导致拉伸其中的文本,这只会导致控件调整大小以填充可用空间并在其中显示更多文本。 Glyph size is still depended on FontSize property only. 字形大小仍然仅取决于FontSize属性。

If you want to horizontally align TextBox contents, set TextAlignment property to HorizontalAlignment.Center. 如果要水平对齐TextBox内容,请将TextAlignment属性设置为Horizo​​ntalAlignment.Center。 If you want to vertically align TextBox contents, unfortunately there is not a VerticalTextAlignment, but you can set VerticalAlignment to VerticalAlignment.Center (instead of Stretch) so that TextBox positions vertically in middle of it's container. 如果要垂直对齐TextBox的内容,可惜没有VerticalTextAlignment,但是可以将VerticalAlignment设置为VerticalAlignment.Center(而不是Stretch),以便TextBox可以垂直放置在其容器的中间。

And for designing you app to fit all types of devices, you may take a look at guidelines in MSDN: 为了设计适合所有类型设备的应用程序,您可以查看MSDN中的准则:

My personal exprience is that designing for multiple sizes does not mean that you must not hardcore any size at all, or you need to stretch content of a textbox. 我个人的经验是,针对多种尺寸进行设计并不意味着您绝对不能硬着任何尺寸,或者您需要扩展文本框的内容。 It's more a matter of repositioning, hiding/showing elements, in different ways. 更多的是以不同的方式重新定位,隐藏/显示元素。 Take a look at built-in Windows Metro Apps (Now Universal) and how they behave on different sizes. 查看内置的Windows Metro Apps(Now Universal)以及它们在不同大小下的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM