简体   繁体   English

Metro应用程序如何在后面的C#代码中创建分组的GridView

[英]Metro app how to create grouped GridView in the C# code behind

In my metro app I need to show groups of VariableSizeWrapGrid on a GridView. 在我的Metro应用程序中,我需要在GridView上显示多组VariableSizeWrapGrid。 Doing this is straight forward in XAML(by creating ItemsPanelTemplate and GroupStyle). 在XAML中这样做很简单(通过创建ItemsPanelTemplate和GroupStyle)。 But is there a way to do the same in C# code behind. 但是后面有没有办法在C#代码中做同样的事情。

From here : 这里

using System;
using System.Windows;
using System.Windows.Data;

namespace GroupingSample
{
    public partial class Window1 : System.Windows.Window
    {

        public Window1()
        {
            InitializeComponent();
        }

        CollectionView myView;
        private void AddGrouping(object sender, RoutedEventArgs e)
        {
            myView = (CollectionView)CollectionViewSource.GetDefaultView(myItemsControl.ItemsSource);
            if (myView.CanGroup == true)
            {
                PropertyGroupDescription groupDescription
                    = new PropertyGroupDescription("@Type");
                myView.GroupDescriptions.Add(groupDescription);
            }
            else 
                return;
        }

        private void RemoveGrouping(object sender, RoutedEventArgs e)
        {
            myView = (CollectionView)CollectionViewSource.GetDefaultView(myItemsControl.ItemsSource);
            myView.GroupDescriptions.Clear();
        }
    }
}

The key here is that you get the default view off of the ItemsSource and set the grouping on that. 此处的关键是您可以从ItemsSource获取默认视图并在其上设置分组。 This line: 这行:

myView = (CollectionView)CollectionViewSource.GetDefaultView(myItemsControl.ItemsSource);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在c#后面的代码中添加带有objectdatasource的gridview? - how to add gridview with objectdatasource in code behind c#? 如何在 c# 代码后面将值绑定到 gridview 中的超链接 - how to bind value to hyperlink in gridview in c# code behind 如何在后面的代码中访问C#Metro UI中的数据模板内的Control - How to access a Control inside the data template in C# Metro UI in the code behind 在C#背后的代码中使用GridViewRow对象创建GridView行 - Create GridView rows using GridViewRow object in Code Behind Using C# 如何在后面的代码中使用WPF C#创建带有图像的自定义MessageBox? - How to create, in code behind, a Custom MessageBox with Images in WPF C#? 如何在UWP平台中使用背后的C#代码创建DataTemplate? - How to create DataTemplate in UWP platform using C# code behind? 如何从C#应用程序调用服务器中的函数背后的代码? - How to call a code behind function in server from a C# app? 在ac#Metro应用中创建3D立方体 - create a 3D Cube in a c# metro app GridView中的双列,从C#中的后面代码构建 - Double columns in GridView, building from code behind in C# GridView,ItemTemplate,DataTemplate绑定在C#代码后面 - GridView, ItemTemplate, DataTemplate binding in C# code behind
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM