[英]How can I sort a XAML gridview in a Windows 8.1 app?
I have the following xaml code about GridView: 我有以下有关GridView的xaml代码:
<GridView x:Name="ivGridView" Margin="70,40,10,10" SelectionChanged="ivGridView_SelectionChanged">
<GridView.ItemTemplate>
<DataTemplate>
<StackPanel Background="{Binding Color}" HorizontalAlignment="Stretch" VerticalAlignment="Bottom">
<TextBlock Text="{Binding name}" Foreground="White" Margin="10,0,0,0" />
<TextBlock Text="{Binding id}" Foreground="White" Margin="7,0,0,0" FontWeight="Light" />
</StackPanel>
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
How do I implement the sort for the GridView based on the Textblock value which binds to name? 如何基于绑定到名称的Textblock值实现GridView的排序?
You can sort the associated ItemsSource to sort the items in the view. 您可以对关联的ItemsSource进行排序,以对视图中的项目进行排序。
public ObservableCollection<Test> TestOC = new ObservableCollection<Test>();
public MainPage()
{
this.InitializeComponent();
TestOC.Add(new Test() {name="BBB",id="1",Color=new SolidColorBrush(Colors.Red)});
TestOC.Add(new Test() { name = "CCC", id="11", Color = new SolidColorBrush(Colors.Green) });
TestOC.Add(new Test() { name = "AA", id="111", Color = new SolidColorBrush(Colors.Orange) });
var SortResult = TestOC.OrderBy(a => a.name);
ivGridView.ItemsSource =SortResult;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.