设置 Silverlight 文本框控件的相对宽度
我尝试在 stackoverflow 上搜索我的问题的答案,但似乎找不到任何相关内容。
由于我对 Silverlight 比较陌生,我什至不确定这是否可能,但我试图弄清楚是否可以按比例设置 Silverlight 文本框控件的宽度值与其直接父容器?
最好避免对宽度值进行硬编码。假设您想要将一个文本框控件放置在水平对齐的 StackPanel 控件内,并使其宽度始终动态调整为 StackPanel 总宽度的 80%。
这是否可以在您的 xaml 标记中以声明方式执行,或者我是否需要诉诸附加到某些事件处理程序的某些代码隐藏来完成此操作?
仅供参考,我目前正在使用 Visual Web Developer Express 2008 编写我的 silverlight 代码。
提前致谢, 约翰
I tried searching on stackoverflow for an answer to my question but couldn't seem to find anything relevant.
Since I'm relatively new to Silverlight, I'm not even sure if this is possible, but I am trying to figure out if it is possible to set a Silverlight textbox control's width value proportionally to it's immediate parent container?
It would be nice to avoid hard coding a width value. Say you want to place a textbox control inside a horizontally aligned StackPanel control and have it's width always dynamically adjusted to be 80% of the total width of the StackPanel.
Is this possible to do declaratively in your xaml markup, or will I need to resort to some codebehind attached to some event handler to accomplish this?
fyi, I am currently using Visual Web Developer Express 2008 to write my silverlight code.
thanks in advance,
John
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用网格而不是堆栈面板。像这样的东西会起作用。
只需将列定义宽度设置为与您的需求成比例即可。如果您想要特定的宽度,请省略 *(星号)。如果您想要比例,请添加*(星号)并使用您想要的任何方案来确定比例(它们可以加起来达到您想要的任何数字)。在我的示例中,数字相加为 100。但您可以使用小数或其他数字。
Use a Grid instead of a stack panel. Something like this would work.
Just set the columndefinition widths to be proportional to your needs. If you want a specific width, leave out the * (asterisk). If you want proportional, add an * (asterisk) and use whatever scheme you want for determining the proportions (they can add up to whatever number you want). In my example, the numbers add to 100. But you can use fractional numbers, or whatever.
听起来您想要一个
而不是
。只需将 TextBox 放入宽度设置为.8
的列中即可。It sounds like you want a
<Grid>
instead of a<StackPanel>
. Just put the TextBox into a column whose width is set to.8
.