当前位置: 首页>>代码示例>>C#>>正文


C# Predicate.Skip方法代码示例

本文整理汇总了C#中Predicate.Skip方法的典型用法代码示例。如果您正苦于以下问题:C# Predicate.Skip方法的具体用法?C# Predicate.Skip怎么用?C# Predicate.Skip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Predicate的用法示例。


在下文中一共展示了Predicate.Skip方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetSelected

        private static bool SetSelected(ItemsControl parent, Predicate<object>[] predicates)
        {
            if (parent == null)
            {
                return false;
            }

            if (predicates.Count() == 0)
            {
                //
                // No more predicates. All done.
                //
                return true;
            }

            foreach (object child in parent.Items)
            {
                if (predicates.First()(child))
                {
                    if (parent.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
                    {
                        TreeViewItem childNode = parent.ItemContainerGenerator.ContainerFromItem(child) as TreeViewItem;

                        if (childNode != null)
                        {
                            childNode.IsExpanded = true;
                            childNode.Focus();
                            childNode.IsSelected = true;

                            return SetSelected(childNode as ItemsControl, predicates.Skip(1).ToArray());
                        }

                        return false;
                    }
                    else
                    {
                        //
                        // Items aren't available yet.
                        // Register an event handler to continue the search when they become available.
                        //

                        EventHandler statusChangedHandler = null;

                        statusChangedHandler = delegate(object sender, EventArgs e)
                        {
                            ItemContainerGenerator generator = sender as ItemContainerGenerator;

                            if (generator == null || generator.Status != GeneratorStatus.ContainersGenerated)
                            {
                                return;
                            }

                            try
                            {
                                TreeViewItem childNode = generator.ContainerFromItem(child) as TreeViewItem;

                                if (childNode != null)
                                {
                                    childNode.IsExpanded = true;
                                    childNode.Focus();
                                    childNode.IsSelected = true;

                                    if (SetSelected(childNode as ItemsControl, predicates.Skip(1).ToArray()))
                                    {
                                        return;
                                    }
                                }
                            }
                            finally
                            {
                                generator.StatusChanged -= statusChangedHandler;
                            }
                        };

                        parent.ItemContainerGenerator.StatusChanged += statusChangedHandler;

                        //
                        // Return true here, even though we haven't worked through all the
                        // predicates.
                        //
                        // (I would put a wait handle here and wait for the status changed
                        // delegate, but everything happens in the same thread.)
                        //

                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:wfraser,项目名称:FooSync,代码行数:91,代码来源:TreeViewExtensions.cs


注:本文中的Predicate.Skip方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。