本文整理汇总了C#中Windows.UI.Xaml.UIElement.GetAncestors方法的典型用法代码示例。如果您正苦于以下问题:C# UIElement.GetAncestors方法的具体用法?C# UIElement.GetAncestors怎么用?C# UIElement.GetAncestors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.UI.Xaml.UIElement
的用法示例。
在下文中一共展示了UIElement.GetAncestors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectItem
internal async Task<bool> SelectItem(UIElement element, bool refreshOnFail = false)
{
var ancestors = new[] { element }.Concat(element.GetAncestors()).ToList();
if (this.RootElements == null || this.RootElements.Count == 0)
{
await Refresh();
}
var vm = this.RootElements[0] as DependencyObjectViewModel;
var ancestorIndex = ancestors.IndexOf(vm.Model);
if (ancestorIndex < 0)
{
for (int i = 1; i < this.RootElements.Count && ancestorIndex < 0; i++)
{
// Handling popups
var popup = this.RootElements[i];
if (!popup.IsExpanded)
{
await popup.LoadChildrenAsync();
popup.IsExpanded = true;
}
if (popup.Children.Count > 0)
{
vm = popup.Children[0] as DependencyObjectViewModel;
ancestorIndex = ancestors.IndexOf(vm.Model);
}
}
if (ancestorIndex < 0)
{
await Refresh();
ancestorIndex = ancestors.IndexOf(vm.Model);
}
}
if (ancestorIndex < 0)
{
System.Diagnostics.Debug.WriteLine("Something's wrong, but let's not throw exceptions here.");
//Debugger.Break();
if (refreshOnFail)
{
await Refresh();
return await SelectItem(element, false);
}
return false;
}
//Debug.Assert(vm.Model == ancestors[0]);
for (ancestorIndex = ancestorIndex - 1; ancestorIndex >= 0; ancestorIndex--)
{
if (!vm.IsExpanded)
{
await vm.LoadChildrenAsync();
vm.IsExpanded = true;
}
var child =
vm.Children.OfType<DependencyObjectViewModel>()
.FirstOrDefault(dovm => dovm.Model == ancestors[ancestorIndex]);
if (child == null)
{
System.Diagnostics.Debug.WriteLine("Something's wrong, but let's not throw exceptions here.");
//Debugger.Break();
if (refreshOnFail)
{
vm.Children.Clear();
//await vm.LoadPropertiesAsync();
await vm.LoadChildrenAsync();
//if (vm.Parent == null)
//{
// await Refresh();
//}
//else
//{
// // do a partial refresh on the stale subtree
// var i = vm.Parent.Children.IndexOf(vm);
// vm.Parent.Children.RemoveAt(i);
// vm.Parent.Children.Insert(i, new DependencyObjectViewModel(this, vm.Parent, ancestors[ancestorIndex]));
//}
return await SelectItem(element, false);
}
return false;
}
vm = child;
}
await Task.Delay(100);
vm.IsSelected = true;
//.........这里部分代码省略.........