本文整理汇总了C#中IInputElement.GetVisualParent方法的典型用法代码示例。如果您正苦于以下问题:C# IInputElement.GetVisualParent方法的具体用法?C# IInputElement.GetVisualParent怎么用?C# IInputElement.GetVisualParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IInputElement
的用法示例。
在下文中一共展示了IInputElement.GetVisualParent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNext
/// <summary>
/// Gets the next control in the specified navigation direction.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="direction">The navigation direction.</param>
/// <returns>
/// The next element in the specified direction, or null if <paramref name="element"/>
/// was the last in the requested direction.
/// </returns>
public static IInputElement GetNext(
IInputElement element,
FocusNavigationDirection direction)
{
Contract.Requires<ArgumentNullException>(element != null);
Contract.Requires<ArgumentException>(
direction != FocusNavigationDirection.Next &&
direction != FocusNavigationDirection.Previous);
var container = element.GetVisualParent<IInputElement>();
if (container != null)
{
var isForward = IsForward(direction);
var mode = KeyboardNavigation.GetDirectionalNavigation((InputElement)container);
switch (mode)
{
case KeyboardNavigationMode.Continue:
return GetNextInContainer(element, container, direction) ??
GetFirstInNextContainer(element, direction);
case KeyboardNavigationMode.Cycle:
return GetNextInContainer(element, container, direction) ??
GetFocusableDescendent(container, direction);
case KeyboardNavigationMode.Contained:
return GetNextInContainer(element, container, direction);
default:
return null;
}
}
else
{
return GetFocusableDescendents(element).FirstOrDefault();
}
}
示例2: GetNextInTabOrder
/// <summary>
/// Gets the next element in tab order.
/// </summary>
/// <param name="element">The element.</param>
/// <returns>The next element in tab order.</returns>
public static IInputElement GetNextInTabOrder(IInputElement element)
{
Contract.Requires<ArgumentNullException>(element != null);
var container = element.GetVisualParent<IInputElement>();
if (container != null)
{
var mode = KeyboardNavigation.GetTabNavigation((InputElement)container);
switch (mode)
{
case KeyboardNavigationMode.Continue:
return GetNextInContainer(element, container) ??
GetFirstInNextContainer(container);
case KeyboardNavigationMode.Cycle:
return GetNextInContainer(element, container) ??
GetDescendents(container).FirstOrDefault();
default:
return GetFirstInNextContainer(container);
}
}
else
{
return GetDescendents(element).FirstOrDefault();
}
}
示例3: GetFirstInNextContainer
/// <summary>
/// Gets the first item that should be focused in the next container.
/// </summary>
/// <param name="container">The container.</param>
/// <param name="direction">The direction of the search.</param>
/// <returns>The first element, or null if there are no more elements.</returns>
private static IInputElement GetFirstInNextContainer(
IInputElement container,
FocusNavigationDirection direction)
{
var parent = container.GetVisualParent<IInputElement>();
var isForward = IsForward(direction);
IInputElement next = null;
if (parent != null)
{
if (!isForward && parent.CanFocus())
{
return parent;
}
var siblings = parent.GetVisualChildren()
.OfType<IInputElement>()
.Where(FocusExtensions.CanFocusDescendents);
IInputElement sibling;
if (isForward)
{
sibling = siblings.SkipWhile(x => x != container).Skip(1).FirstOrDefault();
}
else
{
sibling = siblings.TakeWhile(x => x != container).LastOrDefault();
}
if (sibling != null)
{
if (sibling.CanFocus())
{
next = sibling;
}
else
{
next = isForward ?
GetFocusableDescendents(sibling).FirstOrDefault() :
GetFocusableDescendents(sibling).LastOrDefault();
}
}
if (next == null)
{
next = GetFirstInNextContainer(parent, direction);
}
}
else
{
next = isForward ?
GetFocusableDescendents(container).FirstOrDefault() :
GetFocusableDescendents(container).LastOrDefault();
}
return next;
}
示例4: GetFocusScopeAncestors
/// <summary>
/// Gets the focus scope ancestors of the specified control, traversing popups.
/// </summary>
/// <param name="control">The control.</param>
/// <returns>The focus scopes.</returns>
private static IEnumerable<IFocusScope> GetFocusScopeAncestors(IInputElement control)
{
while (control != null)
{
var scope = control as IFocusScope;
if (scope != null)
{
yield return scope;
}
control = control.GetVisualParent<IInputElement>() ??
((control as IHostedVisualTreeRoot)?.Host as IInputElement);
}
}
示例5: GetLastInPreviousContainer
/// <summary>
/// Gets the last item that should be focused in the previous container.
/// </summary>
/// <param name="container">The container.</param>
/// <returns>The next element, or null if there are no more elements.</returns>
private static IInputElement GetLastInPreviousContainer(IInputElement container)
{
var parent = container.GetVisualParent<IInputElement>();
IInputElement next = null;
if (parent != null)
{
var sibling = parent.GetVisualChildren()
.OfType<IInputElement>()
.Where(CanFocusDescendent)
.TakeWhile(x => x != container)
.LastOrDefault();
if (sibling != null)
{
if (CanFocus(sibling))
{
next = sibling;
}
else
{
next = GetDescendents(sibling).LastOrDefault();
}
}
if (next == null)
{
next = GetLastInPreviousContainer(parent);
}
}
else
{
next = GetDescendents(container).LastOrDefault();
}
return next;
}