1

我正在根据我的需要调整这个解决方案:http ://www.abhisheksur.com/2010/08/woring-with-icollectionviewsource-in.html

列表视图的 XAML 部分是:

    <ListView Grid.Row="1" Name="lvIcons" ItemsSource="{Binding}">
        <ListView.GroupStyle>
            <GroupStyle>
                <GroupStyle.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}" />
                    </DataTemplate>
                </GroupStyle.HeaderTemplate>
            </GroupStyle>
        </ListView.GroupStyle>
        <ListView.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel Width="{Binding (FrameworkElement.ActualWidth), 
        RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"
        ItemWidth="{Binding (ListView.View).ItemWidth, 
        RelativeSource={RelativeSource AncestorType=ListView}}"
        MinWidth="{Binding ItemWidth, RelativeSource={RelativeSource Self}}"
        ItemHeight="{Binding (ListView.View).ItemHeight, 
        RelativeSource={RelativeSource AncestorType=ListView}}" />
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>

    </ListView>

我有一个按钮来控制是否要显示分组,这个按钮背后的代码是:

private void btnGroup_Click(object sender, RoutedEventArgs e)
    {
        this.Source.GroupDescriptions.Clear();

        PropertyInfo pinfo = typeof(country_icon).GetProperty(cmbGroups.Text);
        if (pinfo != null)
            this.Source.GroupDescriptions.Add(new ropertyGroupDescription(pinfo.Name));

    }

当分组打开时,包裹面板工作得很好(我按图标上的整数属性分组)

包装好

但是当分组没有打开时,没有包装:

不包装好

我不担心不同大小的图标 - 我稍后会解决这个问题。

未分组时如何修复包装?是否使用了不同的模板?

感谢这个问题的答案WPF ListView 与项目的水平排列?帮助我到达现在的位置。

4

0 回答 0