首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DataGrid中的Silverlight DataGridRows -如何有选择地隐藏它们?

DataGrid中的Silverlight DataGridRows -如何有选择地隐藏它们?
EN

Stack Overflow用户
提问于 2009-01-27 21:46:37
回答 2查看 3.9K关注 0票数 1

我有一个正在更新的DataGrid的ObservableCollection。

要点:我想过滤(折叠)行,而不从集合中删除它们。

有没有办法做到这一点,或者像普通的.Net一样在网格上放置一个视图?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-01-29 11:46:14

我刚做了published a post on my blog that addresses this exact issue

这篇文章附带了一个简单的演示应用程序,演示了如何实现你想要的东西。

该解决方案应该足够通用,以便可重用,并基于以下自定义扩展方法:

代码语言:javascript
复制
public static class Extensions
{
    /// <summary>
    /// Applies an action to each item in the sequence, which action depends on the evaluation of the predicate.
    /// </summary>
    /// <typeparam name="TSource">The type of the elements of source.</typeparam>
    /// <param name="source">A sequence to filter.</param>
    /// <param name="predicate">A function to test each element for a condition.</param>
    /// <param name="posAction">An action used to mutate elements that match the predicate's condition.</param>
    /// <param name="negAction">An action used to mutate elements that do not match the predicate's condition.</param>
    /// <returns>The elements in the sequence that matched the predicate's condition and were transformed by posAction.</returns>
    public static IEnumerable<TSource> ApplyMutateFilter<TSource>(this IEnumerable<TSource> source,
                                                                  Func<TSource, bool> predicate,
                                                                  Action<TSource> posAction,
                                                                  Action<TSource> negAction)
    {
        if (source != null)
        {
            foreach (TSource item in source)
            {
                if (predicate(item))
                {
                    posAction(item);
                }
                else
                {
                    negAction(item);
                }
            }
        }

        return source.Where(predicate);
    }
}
票数 1
EN

Stack Overflow用户

发布于 2009-01-29 21:08:16

如果你在你的可观察集合上有一个视图,你就可以做到这一点。我写了一篇关于过滤Silverlight数据网格的文章。您有一个可以添加任何IFilter的FilteredCollectionView。这是这篇文章的链接:

http://www.codeproject.com/KB/silverlight/autofiltering_silverlight.aspx

希望能对你有所帮助。

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

https://stackoverflow.com/questions/485437

复制
相关文章

相似问题

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