【发布时间】:2015-07-16 22:00:24
【问题描述】:
我希望 Button 控件的内容包含统一的网格。但是,Button 控件似乎不允许其子内容控件进行拉伸。我的 UniformGrid 总是被压缩以适应它自己的内容。它允许我设置宽度,但即使我明确设置了 HorizontalAlignment,它也不会自动拉伸。我错过了什么?
<Button Margin="0,4,0,4">
<ItemsControl ItemsSource="{Binding Zones}" Focusable="False">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="{Binding Zones.Count}" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<wpfApplication2:ControllerZoneControl DataContext="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Button>
我可以使用以下命令强制设置宽度,但对我来说这似乎很老套。
<UniformGrid Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}}, Path=ActualWidth}" Columns="{Binding Zones.Count}" />
【问题讨论】:
-
你能把你的“ControllerZoneControl”中的代码贴出来吗?
-
您的“hack”通常是正确的解决方案。但是你不能将Button的
HorizontalContentAlignment设置为Stretch吗? -
这是拼图中缺失的部分!
标签: wpf wpf-controls