Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.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
C# “网格松动”;“伸展”-财产_C#_Wpf - Fatal编程技术网

C# “网格松动”;“伸展”-财产

C# “网格松动”;“伸展”-财产,c#,wpf,C#,Wpf,我正在尝试使用网格创建ItemsControl,以确保占用整个空间并在列之间拆分。例如,DataTemplates中的类似内容: 网格控件是我找到的唯一一个具有此属性的控件。 由于网格不能很好地与动态单元配合使用,我在这里使用了答案,以绑定到我的模型: 到目前为止,我的代码是这样的: <DataTemplate x:Key="DtTaskBoardSection" DataType="{x:Type m:TaskBoardSection}"> <uc:TaskBoa

我正在尝试使用网格创建ItemsControl,以确保占用整个空间并在列之间拆分。例如,DataTemplates中的类似内容:

网格控件是我找到的唯一一个具有此属性的控件。 由于网格不能很好地与动态单元配合使用,我在这里使用了答案,以绑定到我的模型:

到目前为止,我的代码是这样的:

<DataTemplate x:Key="DtTaskBoardSection" DataType="{x:Type m:TaskBoardSection}">
    <uc:TaskBoardSectionControl
        AttachedTaskBoardSection="{Binding}" />
</DataTemplate>

<DataTemplate x:Key="DtTaskBoardSectionList" DataType="{x:Type m:TaskBoardSectionList}">
    <ItemsControl ItemsSource="{Binding}" ItemTemplate="{StaticResource DtTaskBoardSection}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <Grid 
                    ShowGridLines="True"
                    xf:DynamicGridSizeBinding.ColumnCount="{Binding Count}" 
                    Background="LightGreen" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>

        <!--https://stackoverflow.com/questions/2432847/bind-grid-row-grid-column-inside-a-datatemplate-->
        <ItemsControl.ItemContainerStyle>
            <Style TargetType="ContentPresenter">
                <Setter Property="HorizontalAlignment" Value="Stretch" />
                <Setter Property="Grid.Column" Value="{Binding Sequence}" />
            </Style>
        </ItemsControl.ItemContainerStyle>
    </ItemsControl>
</DataTemplate>

不幸的是,在实际项目中,它现在只是像StackPanel一样堆叠控件:

浅绿色背景代表网格,但我希望我的两个测试控件只占每个控件的50%,事实并非如此

不幸的是,我很难深入了解ItemTemplate逻辑的内部结构,但覆盖它似乎不仅会导致网格覆盖直接项属性,还会覆盖内容对齐的一些重要属性。
我想我这里缺少了一部分逻辑,你能给我一个提示,我缺少WPF模板过程的哪一部分吗?

你的
DynamicGridSizeBinding.ColumnCount
属性可能正在创建列定义,其宽度设置为
Auto
,虽然它应该是星号:

new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) };
但是,对于大小均匀的列,您不需要附加
ColumnCount
属性的网格。最好将UniformGrid与单行一起使用:

<ItemsControl ItemsSource="{Binding}" ItemTemplate="{StaticResource DtTaskBoardSection}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid Rows="1"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>


请说明如何创建列定义。似乎已将其宽度的GridUnitType设置为自动而不是星形。是否查看了
UniformGrid
?从我所看到的情况来看,它应该在这里工作,只需设置
Rows=1
。不需要奇怪的
Grid
extensions.Uff,这是一个双重假设:你是对的,我没有使用扩展的一个属性,这导致宽度自动变宽。更进一步,UniformGrid也可以工作。有趣的是,我想我使用了UniformGrid。不过,非常感谢!