/// <summary> /// 设置焦点,若参数为null,则保持当前焦点位置 /// </summary> /// <param name="target">设置的元素</param> public void SetFlow(ComponentBase target) { if (target == null) { return; } target.UIInvoke(new Action(() => { if (CurrentElement != null && target == CurrentElement) { return; } //若传入要素的焦点控制器与当前的不一致,则不执行跳转 var fm = FlowManager.GetManagerInstance(target); if (fm != this) { return; } //直接跳转到目标元素 if (IsFlowable(target)) { RaiseEnterEvent(target); CurrentElement = target; } else if (CurrentElement == null) { ReSetFlow(); } })); }
void _target_Ready(object sender, EventArgs e) { _target.Loaded -= _target_Ready; //检查上层是否存在开启焦点的控件,防止嵌套 if (_target.FindVisualTreeAncestor(x => FlowManager.GetIsFlowScope(x)) != null) { throw new NotSupportedException("上层已经开启焦点流程控制,系统不支持嵌套使用!目标:" + _target); } //如果区域的背景为空,会导致鼠标点击事件的穿透,影响控制效果 if (_target.GetValue(Control.BackgroundProperty) == null) { _target.SetValue(Control.BackgroundProperty, Brushes.Transparent); } FlowList = FlowList.Create(_target); //foreach (var item in FlowList) //{ // SetManagerInstance(item, this); //} //如果已经设置好焦点控件,则无须重置 if (CurrentElement == null) { this.MoveFocusHost(FlowNavigation.Top); } }
internal static void SetManagerInstance(DependencyObject d, FlowManager value) { d.SetValue(ManagerInstancePropertyKey, value); }