wpf - 用作 tabitem 的网格的大小问题
我在显示为选项卡(在左侧垂直显示)的菜单时遇到一些问题,
我定义了一个标题模板,它定义了一个由两列组成的网格,其中第一列包含一个文本块,其中包含通过绑定检索的文本。第二列包含一个图像,其可见性与属性相关 - 该图像由验证使用,并在验证另一个视图中输入的数据时显示。
我遇到的问题是让列共享相同的宽度。示例:
Text1| Image
MuchLongerText| Image
这看起来有点奇怪,所以我试图让图像对齐,但似乎无法做到这一点。 HeaderTemplate 有一个指定的数据模板,如下所示,
<Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="{Binding Name}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<Image Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Width="20" Height="20" x:Name="ValidationImage" Source="/Images/validationimage.bmp"/> </Grid>
我尝试将其放入堆栈面板并使用共享大小,但没有成功。任何对此的帮助将不胜感激! 干杯 /萨基克21
I am having some problems with a menu that is displayed as tabs (displayed vertically on the left side)
I have defined a headertemplate that defines a grid consisting of two columns where the first holds a textblock with the text retrieved via binding. The second column holds an image whose visibility is tied to a property - this image is used by validation and shown when data entered in another view has been validated.
The problem I have is getting the columns to share the same width. Example:
Text1| Image
MuchLongerText| Image
This looks a bit wonky and so am trying to get the Images to line up but can't seem to do this. The HeaderTemplate has a datatemplate specified as below
<Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="{Binding Name}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<Image Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Width="20" Height="20" x:Name="ValidationImage" Source="/Images/validationimage.bmp"/> </Grid>
I've tried putting it in a stackpanel and using sharedsize but no luck. Any help with this would be much appreciated!
Cheers
/Sakic21
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下
Grid.IsSharedSizeScope
和DefinitionBase.SharedSizeGroup
属性。Take a look at the
Grid.IsSharedSizeScope
andDefinitionBase.SharedSizeGroup
properties.