protected override void AddChild(object value) { if (value is Button btn) { btn.Style = btnConsole.Style; if (btn.Content is string s) { btn.Content = null; var lbl = new Label() { Content = s }; lbl.SetBinding(Label.ForegroundProperty, new Binding("Foreground") { Source = btn }); btn.Content = lbl; } //btn.chr WindowChrome.SetIsHitTestVisibleInChrome(btn, true); panelButtonBar.Children.Add(btn); } else { base.AddChild(value); } }
public LoginUI() { InitializeComponent(); var v = this.WindowStyle; var vvv = this.ResizeMode; WindowChrome.SetIsHitTestVisibleInChrome(this, true); //MahApps.Metro.Behaviors.BorderlessWindowBehavior }
/// <summary> /// Called when the <see cref="P:System.Windows.Controls.ContentControl.Content"/> property changes. /// </summary> /// <param name="oldContent">A reference to the root of the old content tree.</param><param name="newContent">A reference to the root of the new content tree.</param> protected override void OnContentChanged(object oldContent, object newContent) { base.OnContentChanged(oldContent, newContent); var content = newContent as IInputElement; if (content != null) { WindowChrome.SetIsHitTestVisibleInChrome(content, true); } }
/// <summary> /// Sets the IsHitTestVisibleInChromeProperty to a MetroWindow template child /// </summary> /// <param name="window">The MetroWindow.</param> /// <param name="name">The name of the template child.</param> /// <param name="hitTestVisible"></param> public static void SetIsHitTestVisibleInChromeProperty <T>(this MetroWindow window, string name, bool hitTestVisible = true) where T : class { if (window == null) { throw new ArgumentNullException(nameof(window)); } var inputElement = window.GetPart <T>(name) as IInputElement; Debug.Assert(inputElement != null, $"{name} is not a IInputElement"); if (WindowChrome.GetIsHitTestVisibleInChrome(inputElement) != hitTestVisible) { WindowChrome.SetIsHitTestVisibleInChrome(inputElement, hitTestVisible); } }
public override void OnApplyTemplate() { base.OnApplyTemplate(); this.resizeGrip = this.GetTemplateChild(PART_ResizeGrip) as FrameworkElement; if (this.resizeGrip != null) { this.resizeGrip.Visibility = this.ResizeMode == ResizeMode.CanResizeWithGrip ? Visibility.Visible : Visibility.Collapsed; WindowChrome.SetIsHitTestVisibleInChrome(this.resizeGrip, true); } }
/// <summary> /// When overridden in a derived class, is invoked whenever application code or internal processes call <see cref="M:System.Windows.FrameworkElement.ApplyTemplate"/>. /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); this.UpdateCanUseDwm(); this.UpdateWindowChrome(); if (this.iconImage != null) { this.iconImage.MouseDown -= this.HandleIconMouseDown; } if (this.WindowCommands == null) { this.WindowCommands = new WindowCommands(); } this.iconImage = this.GetTemplateChild(PART_Icon) as FrameworkElement; if (this.iconImage != null) { WindowChrome.SetIsHitTestVisibleInChrome(this.iconImage, true); this.iconImage.MouseDown += this.HandleIconMouseDown; } var partContentPresenter = this.GetTemplateChild(PART_ContentPresenter) as UIElement; if (partContentPresenter != null) { WindowChrome.SetIsHitTestVisibleInChrome(partContentPresenter, true); } var partWindowCommands = this.GetTemplateChild(PART_WindowCommands) as UIElement; if (partWindowCommands != null) { WindowChrome.SetIsHitTestVisibleInChrome(partWindowCommands, true); } // This has to be done when the theme is changed. Otherwise maximized windows have the wrong size. if (this.WindowState == WindowState.Maximized) { this.WindowState = WindowState.Normal; this.WindowState = WindowState.Maximized; } }
/// <summary> /// When overridden in a derived class, is invoked whenever application code or internal processes /// call System.Windows.FrameworkElement.ApplyTemplate(). /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); this.quickAccessToolbarHolder = this.GetTemplateChild("PART_QuickAccessToolbarHolder") as FrameworkElement; this.headerHolder = this.GetTemplateChild("PART_HeaderHolder") as FrameworkElement; this.itemsContainer = this.GetTemplateChild("PART_ItemsContainer") as Panel; this.isAtLeastOneRequiredControlPresent = this.quickAccessToolbarHolder != null || this.headerHolder != null || this.itemsContainer != null; if (this.quickAccessToolbarHolder != null) { WindowChrome.SetIsHitTestVisibleInChrome(this.quickAccessToolbarHolder, true); } }
private static void SetWindowGrayStyle(Window window, DefinedWindowType definedWindowType) { window.BorderBrush = (Brush) new BrushConverter().ConvertFromString("#D0D1D6"); var rootBorder = new Border() { BorderBrush = Brushes.Gainsboro, BorderThickness = new Thickness(1) }; var mainGrid = new Grid(); mainGrid.Background = Brushes.White; mainGrid.ClipToBounds = true; mainGrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); mainGrid.RowDefinitions.Add(new RowDefinition()); WindowChrome.SetIsHitTestVisibleInChrome(window, true); rootBorder.Child = mainGrid; var windowHeaderView = new WindowHeaderView(definedWindowType); windowHeaderView.SetValue(Grid.RowProperty, 0); mainGrid.Children.Add(windowHeaderView); var contentGrid = new Grid(); contentGrid.SetValue(Grid.RowProperty, 1); if (window.Content != null && window.Content is UIElement uiElement) { window.Content = null; contentGrid.Children.Add(uiElement); } mainGrid.Children.Add(contentGrid); window.Content = rootBorder; }
private void EnableCustomChromeHitTest() { WindowChrome.SetIsHitTestVisibleInChrome(this, true); }
public WindowButton() { InitializeComponent(); WindowChrome.SetIsHitTestVisibleInChrome(this, true); IsEnabledChanged += (s, e) => RefreshContent(); }
internal static void SetIsHitTestVisibleInChrome(UIElement element, bool hitTestVisible) { WindowChrome.SetIsHitTestVisibleInChrome(element, hitTestVisible); }
void Initialize() { Window_Border = new Border(); this.Content = Window_Border; Window_Border.BorderThickness = new Thickness(1); Window_Border.Background = new SolidColorBrush(Color.FromRgb(56, 56, 56)); Window_Border.ClipToBounds = true; Window_Border.Child = Window_Grid; DarkenOverlay.Background = Brushes.Black; DarkenOverlay.Opacity = 0; DarkenOverlay.Visibility = System.Windows.Visibility.Collapsed; DarkenOverlay.BorderThickness = new Thickness(0); DarkenOverlay.IsHitTestVisible = false; Window_Grid.Children.Add(Window_TitleGrid); Window_Content_Grid.Children.Add(ContentPlaceHolder); Window_Grid.Children.Add(Window_Content_Grid); Window_Grid.Children.Add(DarkenOverlay); #region TITLE_BAR Window_TitleGrid.ClipToBounds = true; Window_TitleGrid.Height = TITLE_BAR_HEIGHT; Window_TitleGrid.VerticalAlignment = System.Windows.VerticalAlignment.Top; Window_TitleGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; Window_TitleGrid.Children.Add(TitleIcon); Window_TitleGrid.Children.Add(Window_TitleLabel); Window_TitleGrid.Children.Add(Window_Button_Close); Window_TitleGrid.Children.Add(Window_Button_Maximize); Window_TitleGrid.Children.Add(Window_Button_Minimize); Window_TitleLabel.VerticalAlignment = System.Windows.VerticalAlignment.Top; Window_TitleLabel.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; Window_TitleLabel.Height = TITLE_BAR_HEIGHT - 2; Window_TitleLabel.VerticalContentAlignment = System.Windows.VerticalAlignment.Center; Window_TitleLabel.Margin = new Thickness(30, 0, 140, 0); Window_TitleLabel.Foreground = Brushes.White; Window_Button_Close.MouseEnter += Window_Button_MouseEnter; Window_Button_Close.MouseLeave += Window_Button_MouseLeave; Window_Button_Close.Click += Window_Close; Window_Button_Close.Content = 'r'; Window_Button_Close.FontFamily = new System.Windows.Media.FontFamily("Webdings"); Window_Button_Close.FontSize = 11; Window_Button_Close.Height = 19; Window_Button_Close.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; Window_Button_Close.VerticalAlignment = System.Windows.VerticalAlignment.Top; Window_Button_Close.Padding = new Thickness(0, -CHROME_BUTTON_TOP_MARGIN - 1, 0, 0); Window_Button_Close.Foreground = Brushes.Black; Window_Button_Close.BorderThickness = new Thickness(1); Window_Button_Close.FontWeight = FontWeights.Bold; Window_Button_Close.Width = X_BUTTON_NORMAL_WIDTH; Window_Button_Close.Margin = new Thickness(0, CHROME_BUTTON_TOP_MARGIN, 5, 0); Window_Button_Close.Focusable = false; WindowChrome.SetIsHitTestVisibleInChrome(Window_Button_Close, true); Window_Button_Maximize.MouseEnter += Window_Button_MouseEnter; Window_Button_Maximize.MouseLeave += Window_Button_MouseLeave; Window_Button_Maximize.Click += Window_MaximizeRestore; Window_Button_Maximize.Content = '1'; Window_Button_Maximize.FontFamily = new System.Windows.Media.FontFamily("Webdings"); Window_Button_Maximize.FontSize = 11; Window_Button_Maximize.Height = 19; Window_Button_Maximize.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; Window_Button_Maximize.VerticalAlignment = System.Windows.VerticalAlignment.Top; Window_Button_Maximize.Padding = new Thickness(0, -CHROME_BUTTON_TOP_MARGIN - 1, 0, 0); Window_Button_Maximize.Foreground = Brushes.Black; Window_Button_Maximize.BorderThickness = new Thickness(1); Window_Button_Maximize.FontWeight = FontWeights.Bold; Window_Button_Maximize.Width = 30; Window_Button_Maximize.Margin = new Thickness(0, CHROME_BUTTON_TOP_MARGIN, 52, 0); Window_Button_Maximize.Focusable = false; WindowChrome.SetIsHitTestVisibleInChrome(Window_Button_Maximize, true); Window_Button_Minimize.MouseEnter += Window_Button_MouseEnter; Window_Button_Minimize.MouseLeave += Window_Button_MouseLeave; Window_Button_Minimize.Click += Window_Minimize; Window_Button_Minimize.Content = '0'; Window_Button_Minimize.FontFamily = new System.Windows.Media.FontFamily("Webdings"); Window_Button_Minimize.FontSize = 11; Window_Button_Minimize.Height = 19; Window_Button_Minimize.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; Window_Button_Minimize.VerticalAlignment = System.Windows.VerticalAlignment.Top; Window_Button_Minimize.Padding = new Thickness(0, -CHROME_BUTTON_TOP_MARGIN - 1, 0, 0); Window_Button_Minimize.Foreground = Brushes.Black; Window_Button_Minimize.BorderThickness = new Thickness(1); Window_Button_Minimize.FontWeight = FontWeights.Bold; Window_Button_Minimize.Width = 30; Window_Button_Minimize.Margin = new Thickness(0, CHROME_BUTTON_TOP_MARGIN, 81, 0); Window_Button_Minimize.Focusable = false; WindowChrome.SetIsHitTestVisibleInChrome(Window_Button_Minimize, true); #endregion #region COLOR_PICKER foreach (ThemeColors t in AvailableThemeColors) { MenuItem NewItem = new MenuItem(); NewItem.Header = t; NewItem.Click += (o, e) => { ThemeColor = (ThemeColors)((MenuItem)e.Source).Header; }; ColorPicker.Items.Add(NewItem); } //Window_TitleGrid.ContextMenu = ColorPicker; #endregion Window_Button_Close.Style = (Style)this.FindResource("Window_Button_Close"); Window_Button_Maximize.Style = (Style)this.FindResource("Window_Button_Maximize"); Window_Button_Minimize.Style = (Style)this.FindResource("Window_Button_Minimize"); Window_TitleGrid.Style = (Style)this.FindResource("Window_Frame_Title_Bar"); Window_Border.Style = (Style)this.FindResource("Window_Frame_Border"); TitleEnabledBackground = Window_TitleGrid.Background.CloneCurrentValue(); TitleDisabledBackground = TitleEnabledBackground.CloneCurrentValue(); TitleDisabledBackground.Opacity = 0.4; TitleEnabledBackground.Freeze(); TitleDisabledBackground.Freeze(); }