设置组样式时,通过ListBox样式数据三角形设置ItemsPanel

时间:2015-05-26 12:38:47

标签: wpf wpf-controls .net-4.5

我有一个ItemsControl,我已经设置了GroupStyle。

<ListBox.GroupStyle>
  <GroupStyle>
    <GroupStyle.Panel>
      <ItemsPanelTemplate>
        <StackPanel Orientation="Horizontal" IsItemsHost="True" />
      </ItemsPanelTemplate>
    </GroupStyle.Panel>
  </GroupStyle>
</ListBox.GroupStyle>

此样式将水平排列所有组。基于某些条件,我需要安排组内的项目。例如,如果满足某些条件,则每个组中的项目的面板将为WrapPanel,否则为Canvas。

如果没有设置GroupStyle,我可以这样做:

<ListBox.Style>
  <Style TargetType="ListBox">
    <Setter Property="ItemsPanel">
      <Setter.Value>
        <ItemsPanelTemplate>
          <Canvas IsItemsHost="True" />
        </ItemsPanelTemplate>
      </Setter.Value>
    </Setter>
    <Style.Triggers>
      <DataTrigger Binding="{Binding SomeCondition}" Value="True">
        <Setter Property="ItemsPanel">
          <Setter.Value>
            <ItemsPanelTemplate>
              <StackPanel Orientation="Horizontal" IsItemsHost="True" />
            </ItemsPanelTemplate>
          </Setter.Value>
        </Setter>
      </DataTrigger>
    </Style.Triggers>
  </Style>
</ListBox.Style>

谁能告诉我如何将两者合并?

0 个答案:

没有答案
相关问题