Silverlight 多行文本框 [英] Silverlight multiple line textbox

查看:36
本文介绍了Silverlight 多行文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了几个代码片段,其中人们建议 Silverlight 中文本框的 AcceptsReturn 属性将启用多行.

I have looked at several code snippets where people suggest that the AcceptsReturn property of a textbox in Silverlight will enable multiple lines.

然而,我的问题是当我添加具有所述属性的文本框并明确设置高度或允许它填充容器时,文本垂直位于文本框的中间.

My problem however is when I add a textbox with said property and explicity set the height or allow it to fill the container, the text sits vertically in the middle of the textbox.

<Grid x:Name="LayoutRoot" >
    <TextBox TextWrapping="Wrap" Text="TextBox" AcceptsReturn="True"/>
</Grid>

我需要将文本锚定到文本框的顶部.

I need the text to anchor to the top of the textbox.

推荐答案

确保在这种情况下,文本框没有覆盖默认预期行为的隐式样式.就我而言,我使用的是 Microsoft 的 Cosmopolitan 主题,它对 TextBox 元素具有隐式样式,无法产生正确的行为.

Ensure there is not an implicit style for the text box which is overriding the default expected behavior in this case. IN my case I was using the Cosmopolitan Theme from Microsoft and it had an implicit style for TextBox elements that did not produce the proper behavior.

在该主题的资源中,如果您查看 CoreStyles.xaml 文件中的 DefaultTextBoxStyle,您会在第 448 行找到 VerticalAlignment 设置为 Center 的 ScrollViewer.将此调整到顶部解决了我的问题.

In the resources from that theme if you look at the DefaultTextBoxStyle in the CoreStyles.xaml file, at line 448 you will find the ScrollViewer with a VerticalAlignment set to Center. Adjusting this to top solved my problem.

这篇关于Silverlight 多行文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆