首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何对组合框的可观察集合进行排序

如何对组合框的可观察集合进行排序
EN

Stack Overflow用户
提问于 2012-04-18 00:04:53
回答 1查看 880关注 0票数 2

我有查看源代码

代码语言:javascript
复制
<view:ValidationBaseView x:Class="test.View.test"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:res="clr-namespace:test.Resources"
    xmlns:local="clr-namespace:test"
    xmlns:view="clr-namespace:test.View"
    xmlns:viewModel="clr-namespace:test.ViewModel"
    Height="Auto" Width="Auto">

    <UserControl.DataContext>
        <viewModel:testviewmodelx:Name="testview"/>
    </UserControl.DataContext>

然后我有了我的UI元素,我已经将组合框与ObservableCollection绑定在一起。但我知道我需要在组合中有排序的值。

代码语言:javascript
复制
<ComboBox Grid.Column="0" 
          Grid.Row="3" 
          x:Name="combo1" 
          Margin ="0" 
          ItemsSource="{Binding Path=test}" 
          DisplayMemberPath="testpath"/>
EN

回答 1

Stack Overflow用户

发布于 2012-04-18 00:11:17

使用ICollectionView。如下所示:

代码语言:javascript
复制
// this is your existing collection of items
var items = ...;

var cv = new ListCollectionView(items);

// this will sort by the Foo property of each item
cv.SortDescriptions.Add(new SortDescription("Foo"));

在您的视图中,绑定到集合视图,而不是原始项。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10194850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档