本文整理汇总了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;
}