Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 用相同宽度大小的元素填充ItemsCommrol中的所有可用空间_Wpf_Xaml - Fatal编程技术网

Wpf 用相同宽度大小的元素填充ItemsCommrol中的所有可用空间

Wpf 用相同宽度大小的元素填充ItemsCommrol中的所有可用空间,wpf,xaml,Wpf,Xaml,我有一个ItemsControl,ItemsPanel由DockPanel制作 在DockPanel内部,我可以有一个、两个或三个按钮。问题源于按钮的宽度:我希望三个元素具有相同的大小,但元素采用了它们所需的大小(最后一个元素采用了多余的宽度,因为LastChildFill为true) 我可以在不手动提供按钮大小的情况下为按钮提供相同的宽度吗 <ItemsControl ItemTemplate="{StaticResource Template1}" ItemsSource="{

我有一个ItemsControl,ItemsPanel由DockPanel制作

在DockPanel内部,我可以有一个、两个或三个按钮。问题源于按钮的宽度:我希望三个元素具有相同的大小,但元素采用了它们所需的大小(最后一个元素采用了多余的宽度,因为LastChildFill为true)

我可以在不手动提供按钮大小的情况下为按钮提供相同的宽度吗

    <ItemsControl ItemTemplate="{StaticResource Template1}" ItemsSource="{Binding Path=options, Mode=OneWay}" ItemsPanel="{StaticResource Panel1}" HorizontalContentAlignment="Stretch"/>

    <ItemsPanelTemplate x:Key="Panel1">
        <DockPanel Height="Auto" Width="Auto" LastChildFill="True"/>
    </ItemsPanelTemplate>

    <DataTemplate x:Key="BasicasTemplateOpciones"  DataType="{x:Type local:MyOption}">
        <Grid HorizontalAlignment="Stretch">
            <Button DataContext="{Binding}" HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" >
                <Button.Template>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Center">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
                                    <TextBlock HorizontalAlignment="Right" VerticalAlignment="Stretch"/>
                                </StackPanel>
                            </Grid>
                    </ControlTemplate>
                </Button.Template>
            </Button>
        </Grid>
    </DataTemplate>

A
UniformGrid
只有一行,它可以执行您想要的操作:

<ItemsPanelTemplate x:Key="Panel1">
    <UniformGrid Rows="1" />
</ItemsPanelTemplate>

例如:


福
福
酒吧
福
酒吧
巴兹

A
UniformGrid
只有一行,它可以执行您想要的操作:

<ItemsPanelTemplate x:Key="Panel1">
    <UniformGrid Rows="1" />
</ItemsPanelTemplate>

例如:


福
福
酒吧
福
酒吧
巴兹