Nested ItemsControl Orientation

一世执手 提交于 2020-01-06 18:43:45

问题


I have a nested ItemsControl. My data structure is an ObservableCollection of Campaigns which consist of a Campaign class and an observableCollection of Data counts (total, assigned, unassigned, closed). What I need is the following:

CAMPAIGN.NAME
     TOTAL     UNASSIGNED     ASSIGNED     CLOSED
CAMPAIGN.NAME
     TOTAL     UNASSIGNED     ASSIGNED     CLOSED

I am able to get the first part of this, but for some reason it will not honor the orientation for the second ItemsControl. What am I missing? My XAML is:

<ItemsControl x:Name="icCampaignChicklets" ItemsSource="{Binding CampChicks}" Grid.Row="1">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Vertical" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Grid x:Name="gridContent">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="20" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <TextBlock x:Name="CampaignHeader" Height="20" Text="{Binding Path=Campaign.Name}" Grid.Row="1"  VerticalAlignment="Top" TextWrapping="Wrap" HorizontalAlignment="Left" />
                    <StackPanel Grid.Row="1" Orientation="Horizontal" Margin="10">
                        <ItemsControl x:Name="icChicklets" ItemsSource="{Binding Path=Data}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Border Width="150" Height="140" Background="{Binding Background}" Cursor="Hand"
                                    MouseLeftButtonDown="Chicklet_MouseLeftButtonDown"
                                    >
                                        <Grid x:Name="gridContent" Margin="8,4">
                                            <TextBlock Text="{Binding Caption}" Foreground="White" FontSize="17" />
                                            <TextBlock Text="{Binding CountCaption, Mode=OneWay}" Foreground="White" FontSize="45" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="7" />
                                            <TextBlock Text="Ú" Foreground="#99ffffff" FontSize="30" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="3,5" FontFamily="Wingdings 3" />
                                        </Grid>
                                    </Border>
                                </DataTemplate>

                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </StackPanel>
                </Grid>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

回答1:


If you want to change the orientation of the contents of an ItemsControl, set its ItemsPanel property like so:

<ItemsControl
    ...attributes...
    >
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>

Wrapping it in a horizontally-oriented parent StackPanel will merely arrange it and its siblings horizontally, but in this particular case it has no siblings.



来源:https://stackoverflow.com/questions/38703963/nested-itemscontrol-orientation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!