改变的ListView针对不同类别的项目(启用/禁用)GroupStyle [英] Changing (Enable/Disable) GroupStyle in ListView for different category items

查看:401
本文介绍了改变的ListView针对不同类别的项目(启用/禁用)GroupStyle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能之间的 GroupStyles 用于切换的ListView 根据在运行时的一些情况?比如我需要使用默认的项目,对具有 GroupStyle 头名称为空,如果不为空则使用自定义的 GroupStyle 主题?我试图 GroupStyleSelector ,它不工作,因为它适用于多层次分组,并在我的情况下,我只有一个级别的分组。

How can I switch between GroupStyles for a ListView based on some conditions at run time? For instance I need to use Default for items that that have GroupStyle Header name null, and if it is not null then use the custom GroupStyle theme? I tried GroupStyleSelector, and it doesn't work, because it works for multi level grouping, and in my case I have only one level grouping.

如果是的话,怎么样?

自定义 GroupStyle

    <Style x:Key="grouping"
           TargetType="{x:Type GroupStyle}">
        <Setter Property="ContainerStyle">
            <Setter.Value>
                <Style TargetType="{x:Type GroupItem}">
                    <Setter Property="Margin"
                            Value="0,0,0,5" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type GroupItem}">
                                <Expander IsExpanded="False"
                                          BorderBrush="#FFA4B97F"
                                          BorderThickness="0,0,0,1">
                                    <Expander.Header>
                                        <DockPanel>
                                            <TextBlock FontWeight="Bold"
                                                       Text="{Binding Name}"
                                                       Margin="0"
                                                       Width="250" />
                                            <TextBlock FontWeight="Bold"
                                                       Text="{Binding Path=Items[0].StartTime, StringFormat=T}" />
                                        </DockPanel>
                                    </Expander.Header>
                                    <Expander.Content>
                                        <ItemsPresenter />
                                    </Expander.Content>
                                </Expander>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>                    
    </Style>

非常感谢。

真诚的,
弗拉德。

Sincerely, Vlad.

推荐答案

好吧,

我为它找到解决办法。基本上,我需要建立DataTrigger,并在其中检查类别,如果匹配,使用不同的GroupStyle。这里是例子:

I found solution for it. Basically I needed to build DataTrigger and check for category in it, and if it matches, use different GroupStyle. Here is the example:

  <ControlTemplate TargetType="{x:Type GroupItem}"
                   x:Key="defaultGroup">
       <ItemsPresenter />
  </ControlTemplate>

  <ListView.GroupStyle>
   <GroupStyle >                            
    <GroupStyle.ContainerStyle>
     <Style TargetType="{x:Type GroupItem}">
      <Setter Property="Margin"
        Value="0,0,0,5" />
      <Setter Property="Template">
       <Setter.Value>
        <ControlTemplate TargetType="{x:Type GroupItem}">
         <Expander IsExpanded="False"
             BorderBrush="Black"
             BorderThickness="3"
             Padding="5,1,1,5">
          <Expander.Header>
           <DockPanel>
            <TextBlock FontWeight="Bold"
                 Margin="0"
                 Width="250">
             <TextBlock.Text>
              <MultiBinding StringFormat="{}{0} ({1} jobs)">
               <Binding Path="Name" />
               <Binding Path="ItemCount" />
              </MultiBinding>
             </TextBlock.Text>
            </TextBlock>
            <TextBlock FontWeight="Bold"
                 Text="{Binding Path=Items[0].Category, StringFormat=T}" />
           </DockPanel>
          </Expander.Header>
          <Expander.Content>
           <ItemsPresenter />
          </Expander.Content>
         </Expander>
        </ControlTemplate>
       </Setter.Value>
      </Setter>
      <Style.Triggers>
       <DataTrigger Binding="{Binding Items[0].Category}"
           Value="ABC">
        <Setter Property="Template"
          Value="{StaticResource defaultGroup}" />
       </DataTrigger>
      </Style.Triggers>
     </Style>
    </GroupStyle.ContainerStyle>
   </GroupStyle>
  </ListView.GroupStyle>

这篇关于改变的ListView针对不同类别的项目(启用/禁用)GroupStyle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆