Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.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
GroupBox标题中的Wpf按钮宽度_Wpf_Button_Binding_Header_Width - Fatal编程技术网

GroupBox标题中的Wpf按钮宽度

GroupBox标题中的Wpf按钮宽度,wpf,button,binding,header,width,Wpf,Button,Binding,Header,Width,我有以下代码: <Window.Resources> <DataTemplate x:Key="ParameterItemTemplate"> <my:ParameterItem ParamValue="{Binding Value}" Description="{Binding Name}"/> </DataTemplate> </Window.Resources> <Grid Width="A

我有以下代码:

<Window.Resources>
    <DataTemplate x:Key="ParameterItemTemplate">
        <my:ParameterItem ParamValue="{Binding Value}" Description="{Binding Name}"/>
    </DataTemplate>
</Window.Resources>

<Grid Width="Auto">
    <GroupBox BorderBrush="Black" 
              BorderThickness="2" 
              Width="Auto" 
              HorizontalAlignment="Left" 
              VerticalAlignment="Top">
        <GroupBox.HeaderTemplate>
            <DataTemplate>
                <Button Content="Header" 
                        Width="{Binding RelativeSource={RelativeSource Self}, Path=Width}" 
                        Height="30">
                </Button>
            </DataTemplate>
        </GroupBox.HeaderTemplate>
        <ScrollViewer HorizontalScrollBarVisibility="Auto">
            <ItemsControl x:Name="Test" 
                          ItemsSource="{Binding Items}" 
                          ItemTemplate="{StaticResource ParameterItemTemplate}" >
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel Orientation="Vertical" Height="228"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>
        </ScrollViewer>
    </GroupBox>

</Grid>

当绑定的项目填充my
ItemsControl
时,
分组框的
标题中的
按钮
不会改变其宽度。我有绑定问题吗?

按钮的宽度只适合它的内容。

如果将宽度与自身绑定,您希望得到什么?试一试

<Button Content="Header" 
        Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type GroupBox}}, Path=ActualWidth}" 
        Height="30">

如果将宽度与自身绑定,您希望得到什么?试一试

<Button Content="Header" 
        Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type GroupBox}}, Path=ActualWidth}" 
        Height="30">


谢谢,剩下的唯一问题是我看不到边界的正确部分。这更困难。要解决这个问题,我认为您必须重新模板GroupBox以拉伸内容。开始吧。在您的情况下,使用转换器并从实际宽度中减去一个量可能更简单。这里描述了绑定到实际宽度的技巧:谢谢,剩下的唯一问题是我看不到边框的正确部分。这更困难。要解决这个问题,我认为您必须重新模板GroupBox以拉伸内容。开始吧。在您的情况下,使用转换器并从实际宽度中减去一个量可能更简单。绑定到实际宽度的技巧如下所述: