/// <summary> /// 是否显示蒙板属性修改响应函数 /// </summary> /// <param name="d"></param> /// <param name="e"></param> private static void OnShowMaskGirdPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { WindowEx windowEx = d as WindowEx; if (e.NewValue != e.OldValue) { if ((bool)e.NewValue) { windowEx.maskGrid.Visibility = Visibility.Visible; } else { windowEx.maskGrid.Visibility = Visibility.Collapsed; } } }
/// <summary> /// 去掉蒙板 /// </summary> /// <param name="e"></param> protected override void OnClosed(EventArgs e) { base.OnClosed(e); //蒙板 if (Owner is WindowEx) { WindowEx windowEx = Owner as WindowEx; windowEx.ShowMaskGird = false; } else { Grid maskGrid = Owner.FindName("PART_MaskGrid") as Grid; if (maskGrid != null) { maskGrid.Visibility = Visibility.Collapsed; } } }
/// <summary> /// 初始化控件 /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); ResizeMode = ResizeMode.NoResize; ShowInTaskbar = false; //全局鼠标勾子,闪烁模式窗口自定义标题栏和边框 m_mouseHook = new MouseHook(); m_mouseHook.SetHook(); m_mouseHook.MouseClickEvent += MouseHook_MouseClickEvent; GreateFlashWindowAnimate(); titleBar = GetTemplateChild(PART_TitleBar) as Grid; titleBar.MouseRightButtonUp += TitleBar_MouseRightButtonUp; titleBar.MouseLeftButtonDown += TitleBar_MouseLeftButtonDown; //生成按钮栏 sp_PART_ButtonBarStackPanel = new StackPanel() { Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(0, 0, 10, 0) }; btn_PART_ButtonOK = new Button() { Content = ConfirmButtonContent, Style = Application.Current.TryFindResource("ButtonBlue") as Style, MinWidth = 100, Height = 30, Margin = new Thickness(0, 0, 5, 0), IsDefault = true }; btn_PART_ButtonOK.Click += Btn_PART_ButtonOK_Click; sp_PART_ButtonBarStackPanel.Children.Add(btn_PART_ButtonOK); btn_PART_ButtonYes = new Button() { Content = YesButtonContent, Style = Application.Current.TryFindResource("ButtonBlue") as Style, MinWidth = 100, Height = 30, Margin = new Thickness(0, 0, 5, 0) }; btn_PART_ButtonYes.Click += Btn_PART_ButtonYes_Click; sp_PART_ButtonBarStackPanel.Children.Add(btn_PART_ButtonYes); btn_PART_ButtonNo = new Button() { Content = NoButtonContent, Style = Application.Current.TryFindResource("ButtonBlue") as Style, MinWidth = 100, Height = 30, Margin = new Thickness(0, 0, 5, 0) }; btn_PART_ButtonNo.Click += Btn_PART_ButtonNo_Click; sp_PART_ButtonBarStackPanel.Children.Add(btn_PART_ButtonNo); btn_PART_ButtonCancel = new Button() { Content = CancelButtonContent, Style = Application.Current.TryFindResource("ButtonWhite") as Style, MinWidth = 100, Height = 30, Margin = new Thickness(0, 0, 10, 0) }; btn_PART_ButtonCancel.Click += Btn_PART_ButtonCancel_Click; sp_PART_ButtonBarStackPanel.Children.Add(btn_PART_ButtonCancel); if (MessageBoxButton == MessageBoxButton.OK) { //只有一个按钮,设置按钮居中 sp_PART_ButtonBarStackPanel.HorizontalAlignment = HorizontalAlignment.Center; sp_PART_ButtonBarStackPanel.Margin = new Thickness(0); btn_PART_ButtonOK.Margin = new Thickness(0); } if (MessageBoxButton == MessageBoxButton.OK) { btn_PART_ButtonOK.IsCancel = true; btn_PART_ButtonYes.Visibility = Visibility.Collapsed; btn_PART_ButtonNo.Visibility = Visibility.Collapsed; btn_PART_ButtonCancel.Visibility = Visibility.Collapsed; } else if (MessageBoxButton == MessageBoxButton.OKCancel) { btn_PART_ButtonCancel.IsCancel = true; btn_PART_ButtonYes.Visibility = Visibility.Collapsed; btn_PART_ButtonNo.Visibility = Visibility.Collapsed; } else if (MessageBoxButton == MessageBoxButton.YesNo) { btn_PART_ButtonNo.IsCancel = true; btn_PART_ButtonOK.Visibility = Visibility.Collapsed; btn_PART_ButtonCancel.Visibility = Visibility.Collapsed; } else if (MessageBoxButton == MessageBoxButton.YesNoCancel) { btn_PART_ButtonCancel.IsCancel = true; btn_PART_ButtonOK.Visibility = Visibility.Collapsed; } //生成消息 Grid mainGrid = new Grid(); mainGrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); TextBlock textBlockMsg = new TextBlock() { Text = Message, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(20, 5, 20, 5) }; mainGrid.Children.Add(textBlockMsg);//添加消息到窗口 mainGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(60) }); Grid gridButtonBar = new Grid(); Grid.SetRow(gridButtonBar, 1); gridButtonBar.Children.Add(sp_PART_ButtonBarStackPanel);//添加按钮栏 mainGrid.Children.Add(gridButtonBar); this.Content = mainGrid; if (Owner is WindowEx) { WindowEx windowEx = Owner as WindowEx; windowEx.ShowMaskGird = true; } else { Grid maskGrid = Owner.FindName("PART_MaskGrid") as Grid; if (maskGrid != null) { maskGrid.Visibility = Visibility.Visible; } } }