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
C# 在ItemsControl中将WPF GroupItems保持在一起_C#_Wpf_Mvvm - Fatal编程技术网

C# 在ItemsControl中将WPF GroupItems保持在一起

C# 在ItemsControl中将WPF GroupItems保持在一起,c#,wpf,mvvm,C#,Wpf,Mvvm,我正在尝试按“区域”对集合视图进行分组(始终有5个),我希望实现的是保持所有5个GroupItems垂直堆叠,同时在我的Items控件中每行仅显示7个组 分组示例,其中每个项目有一个日期和3个值,按5个区域分组:AS、CE、KC、NA和LAM: 以下内容使我的GroupItems按我所需的方式堆叠,但由于ItemsPanel是一个DockPanel,它们只会继续向右放置尽可能多的项目: <ItemsControl Grid.Row="1" ItemsSource="{

我正在尝试按“区域”对集合视图进行分组(始终有5个),我希望实现的是保持所有5个GroupItems垂直堆叠,同时在我的Items控件中每行仅显示7个组

分组示例,其中每个项目有一个日期和3个值,按5个区域分组:AS、CE、KC、NA和LAM:

以下内容使我的GroupItems按我所需的方式堆叠,但由于ItemsPanel是一个DockPanel,它们只会继续向右放置尽可能多的项目:

<ItemsControl Grid.Row="1"
          ItemsSource="{Binding DataContext.DailyBuildPlansCollectionView, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
<ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
        <DockPanel HorizontalAlignment="Left"/>
    </ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.Template>
    <ControlTemplate TargetType="ItemsControl">
        <!-- Scrollviewer to let me scroll through the data -->
        <ScrollViewer HorizontalScrollBarVisibility="Auto">
            <ItemsPresenter/>
        </ScrollViewer>
    </ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
    <!-- Template for each individual build plan -->
    <DataTemplate>
        <Border BorderBrush="DarkSlateGray"
                BorderThickness="1">
            <Grid Width="127">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="35"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>

                <!-- Date across top -->
                <Border Background="AntiqueWhite"
                        Grid.Row="0"
                        Grid.Column="1"
                        Grid.ColumnSpan="3"/>
                <TextBlock Grid.Row="0"
                           Grid.Column="1"
                           Grid.ColumnSpan="3"
                           Text="{Binding Day, StringFormat=MMM dd yy}"
                           Margin="2"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           TextAlignment="Center"
                           FontWeight="Bold"/>

                <!-- Region along side -->
                <Border Background="AntiqueWhite"
                        Grid.Row="0"
                        Grid.Column="0"
                        Grid.RowSpan="2"/>
                <TextBlock Grid.Row="0" 
                           Grid.Column="0"
                           Grid.RowSpan="2"
                           Text="{Binding Region}"
                           Margin="2"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           TextAlignment="Center"
                           FontWeight="Bold"/>

                <TextBox Grid.Column="1"
                         Grid.Row="1"
                         Text="{Binding Build, Mode=TwoWay}"
                         Margin="2"
                         TextAlignment="Center"
                         HorizontalAlignment="Center"
                         VerticalAlignment="Center"/>
                <TextBlock Grid.Column="2"
                           Grid.Row="1"
                           Text="{Binding Sales}"
                           Margin="2"
                           TextAlignment="Center"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"/>
                <TextBlock Grid.Column="3"
                           Grid.Row="1"
                           Text="{Binding Inventory}"
                           Margin="2"
                           TextAlignment="Center"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"/>
            </Grid>
        </Border>
    </DataTemplate>
</ItemsControl.ItemTemplate>
<!-- Group Styles - Will be grouped by region -->
<ItemsControl.GroupStyle>
    <GroupStyle>
        <GroupStyle.ContainerStyle>
            <Style TargetType="{x:Type GroupItem}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type GroupItem}">
                            <StackPanel Orientation="Vertical">
                                <ItemsPresenter/>
                            </StackPanel>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </GroupStyle.ContainerStyle>
    </GroupStyle>
</ItemsControl.GroupStyle>

结果:

我以为我可以通过将ItemsPanelTemplate从DockPanel更改为具有7列的UniformGrid来解决这个问题,但这会分散我的组:

我想要达到的最终结果是这样的(划掉日期以减少混淆,它们将继续正常进行):


关于如何实现这一点,您有什么想法吗?

我的第一个猜测是您应该在Grid.Column和Grid.Row值上使用数据绑定。也许在组号上有个mudulo之类的。。。