在WPF中使用Button控件内部的UniformGrid

时间:2015-07-16 22:00:24

标签: wpf wpf-controls

我希望Button控件的内容包含一个统一的网格。但是,Button控件似乎不允许其子内容控件进行拉伸。我的UniformGrid总是被压缩以适应自己的内容。它允许我设置宽度,但即使我明确设置Horizo​​ntalAlignment它也不会自动拉伸。我错过了什么?

        <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}" />

1 个答案:

答案 0 :(得分:0)

在我忘记尝试的所有事情中......将按钮的Horizo​​ntalContentAlignment设置为Stretch是修复。

相关问题