private void OnFunctionSwitchStateChanged(FunctionSwitchStateChangedMessage message) { System.Diagnostics.Debug.Assert(_partialViewDict.ContainsKey(message.FunctionTag), "功能标记不在缓存字典中"); foreach (TabItem tab in this.leftTabControl2.Items) { if (tab.Tag.ToString() == message.FunctionTag) { return; } } // 创建视图 FrameworkElement view = (FrameworkElement)Activator.CreateInstance(_partialViewDict[message.FunctionTag], new object[] { message.FunctionTag }); this.leftTabControl2.Items.Add(new TabItem() { Header = ViewModel.FunctionPanelItems.First(p => p.Tag == message.FunctionTag).Header, Tag = message.FunctionTag, Content = view }); // 再次发送一条通知消息,因为在此之前ViewModel没有收到开关状态改变消息 Messenger.Default.Send(message, view.DataContext.GetType()); }
private void OnFunctionSwitchStateChanged(FunctionSwitchStateChangedMessage message) { if (message.FunctionTag == FunctionTag) { _isOpen = message.IsOpen; if (_isOpen) { PrivateEnableFunction(); } else { PrivateDisableFunction(); } } }