listview wrappanel在取消组合时无法正常工作

时间:2013-07-25 15:10:22

标签: c# wpf listview wrappanel

我正在根据自己的需求调整此解决方案: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));

    }

当打开分组时,wrappanel工作得很好(我按照图标上的整数属性进行分组)

WrappingNicely

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

NotWrappingNicely

我并不担心图标的大小不同 - 我稍后会修复它。

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

感谢这个问题WPF ListView with horizontal arrangement of items?的回答,帮助我找到现在的位置。

0 个答案:

没有答案