【问题标题】:Nested ItemsControl Orientation嵌套项控制方向
【发布时间】:2016-08-01 16:41:01
【问题描述】:

我有一个嵌套的 ItemsControl。我的数据结构是一个 ObservableCollection 的 Campaign,它由一个 Campaign 类和一个 ObservableCollection 的数据计数(总数、已分配、未分配、已关闭)组成。我需要的是以下内容:

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

我能够得到这个的第一部分,但由于某种原因它不会尊重第二个 ItemsControl 的方向。我错过了什么?我的 XAML 是:

<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>

【问题讨论】:

    标签: wpf nested orientation itemscontrol


    【解决方案1】:

    如果您想更改 ItemsControl 内容的方向,请将其 ItemsPanel 属性设置为:

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

    将其包装在水平方向的父级StackPanel 中只会水平排列它及其兄弟姐妹,但在这种特殊情况下,它没有兄弟姐妹。

    【讨论】:

    • 谢谢!我之前尝试过,但 Intellisense 疯了。我当时一定有什么其他疯狂的事情。
    猜你喜欢
    • 2017-01-23
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    • 1970-01-01
    • 2012-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多