【问题标题】:WPF Listbox styleWPF 列表框样式
【发布时间】:2014-04-25 14:25:37
【问题描述】:

我正在关注本教程: http://www.c-sharpcorner.com/uploadfile/dpatra/listbox-group-header-expand-and-collapse-in-wpf/

我尝试用扩展器设计我的列表框。

由于某种原因,我得到了这样的东西:

Title (expander)
 Tiltle(expander)
  Data
  Data
  Data

我不知道是什么导致了双重分组,我需要一些帮助。

这是我的代码:

<ListBox Grid.ColumnSpan="3" Grid.Row="3"
         Name="lbInterfaces"  Background="Transparent" ItemsSource="{Binding InterfacesView }" ItemTemplate="{StaticResource InterfacesDataTemplate}" BorderBrush="Transparent">         
    <ListBox.GroupStyle>
        <GroupStyle ContainerStyle="{StaticResource ContainerStyle}"/>
    </ListBox.GroupStyle>
</ListBox>

<Style x:Key="ContainerStyle" TargetType="{x:Type GroupItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Expander Header="{Binding Name}" IsExpanded="False">
                            <ItemsPresenter />
                        </Expander>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

<DataTemplate x:Key="InterfacesDataTemplate"
              DataType="ca:Interface">
            <Grid>
                <TextBlock Text="{Binding Path=Name}" MouseLeftButtonDown="interface_mouseDown"/>
            </Grid>
        </DataTemplate>

在我的视图模型中:

InterfacesView = CollectionViewSource.GetDefaultView(Interfaces);
InterfacesView.GroupDescriptions.Add(new PropertyGroupDescription("Kind"));
InterfacesView.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));

Kind 是“接口”类中的一个属性

【问题讨论】:

    标签: c# wpf listbox expandablelistview expander


    【解决方案1】:

    把代码改成这样:

        InterfacesView view = CollectionViewSource.GetDefaultView(Interfaces);
        view.GroupDescriptions.Add(new PropertyGroupDescription("Name"));
        view.SortDescriptions.Add(new SortDescription("Name",ListSortDirection.Ascending));
    

    【讨论】:

    • 但我需要将它按 Kind 属性分组。 @TheGaMer123
    • 改变这个:
    • 谢谢大家,最终我的问题是我在另一个位置进行了分组。
    猜你喜欢
    • 2012-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    • 1970-01-01
    • 2019-03-26
    • 1970-01-01
    • 2010-09-26
    相关资源
    最近更新 更多