如何防止 Silverlight xaml Grid 中的列占据整行?
我想在网格中显示两列。第一个是文本块,有时比容纳它的行长。第二个是一个按钮。有没有办法为文本块提供尽可能多的空间,同时仍然为紧随其后的按钮留出空间?
当我使用以下代码时,文本块有时会将按钮推到网格的可视区域之外。
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Description}" HorizontalAlignment="Stretch" />
<Button Margin="4,0" Height="0" Width="16" Grid.Column="1" MinWidth="20" VerticalAlignment="Center" />
</Grid>
我尝试设置第一列定义 Width="*",但是当我希望它位于文本旁边时,按钮始终位于行的最末尾。有什么建议吗?
这是 Silverlight 4 中的。
谢谢。
编辑 我希望网格随着用户更改窗口大小而调整大小,因此对网格大小设置硬限制是不好的。话虽这么说,当 TextBlock 加载以及窗口大小更改时,我可以在后面的代码中手动设置 MaxWidth。它很笨重,但很有效。
I want to display two columns in my Grid. The first is a textblock that is sometimes longer than the row meant to hold it. The second is a button. Is there a way to give the textblock as much room as possible while still leaving room for the button to go immediately after?
When I use the following code, the textblock will sometimes push the button outside the viewable area of the grid.
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Description}" HorizontalAlignment="Stretch" />
<Button Margin="4,0" Height="0" Width="16" Grid.Column="1" MinWidth="20" VerticalAlignment="Center" />
</Grid>
I've tried setting the first column definition Width="*", but then the button is always at the very end of the row, when I want it next to the text. Any suggestions?
This is in Silverlight 4.
Thanks.
EDIT
I want the grid to resize as the user changes the window size, so setting a hard limit on the grid size is no good. That being said, I was able to manually set the MaxWidth in the code behind when the TextBlock loads and when the window changes size. It's clunky, but it works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下肯定会起作用..
将以下行添加到构造函数中的 xaml.cs 文件中..
如果有任何问题,请告诉我。
谢谢..
Following will surely work..
Add Following Line to xaml.cs file in constructor..
Let me know if there is any issue with it.
Thanks..