/// <summary> /// 把 childrenTab 的选择项同步到 View.IsActive 属性上。 /// </summary> /// <param name="parentView"></param> /// <param name="childrenTab"></param> public static void AdaptView(LogicalView parentView, TabControl childrenTab) { //任何一个子 View 可见,整个控件都可见 childrenTab.Visibility = parentView.ChildrenViews.Any(v => v.IsVisible) ? Visibility.Visible : Visibility.Collapsed; //在选择状态发生改变时,设置每个view的Active状态 childrenTab.SelectionChanged += (sender, e) => { //设置每个view的Active状态 if (sender == e.OriginalSource && e.AddedItems.Count > 0) { foreach (TabItem item in e.AddedItems) { var childView = WPFMeta.GetLogicalView(item); childView.IsActive = true; } foreach (TabItem item in e.RemovedItems) { var childView = WPFMeta.GetLogicalView(item); childView.IsActive = false; } e.Handled = true; } }; }
private static TabItem CreateATabItem(Region child) { var label = child.ChildrenLabel ?? child.ControlResult.MainView.Meta.Label; var tabHeader = new Label() { Content = label.Translate() }; tabHeader.MouseDoubleClick += (s, e) => { CommandRepository.TryExecuteCommand(typeof(MaxShowViewCommand), child.ControlResult.MainView); }; var tabItem = new TabItem() { Header = tabHeader, Content = child.ControlResult.Control }; AutomationProperties.SetName(tabItem, label); WPFMeta.SetLogicalView(tabItem, child.ControlResult.MainView); ViewAdapter.AdaptView(child.ControlResult.MainView, tabItem); return(tabItem); }
internal override void OnControlChanged(FrameworkElement control) { base.OnControlChanged(control); WPFMeta.SetLogicalView(control, this); }