How do I remove minimize and maximize from a resizable window in WPF?

后端 未结 7 1157
我寻月下人不归
我寻月下人不归 2020-12-04 12:05

WPF doesn\'t provide the ability to have a window that allows resize but doesn\'t have maximize or minimize buttons. I\'d like to able to make such a window so I can have re

7条回答
  •  無奈伤痛
    2020-12-04 12:31

    If anyone use Devexpress window (DXWindow) accepted answer doesn't work. One ugly approach is

    public partial class MyAwesomeWindow : DXWindow
    {
        public MyAwesomeWIndow()
        {
           Loaded += OnLoaded;
        }
    
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            // hides maximize button            
            Button button = (Button)DevExpress.Xpf.Core.Native.LayoutHelper.FindElementByName(this, DXWindow.ButtonParts.PART_Maximize.ToString());
            button.IsHitTestVisible = false;
            button.Opacity = 0;
    
            // hides minimize button
            button = (Button)DevExpress.Xpf.Core.Native.LayoutHelper.FindElementByName(this, DXWindow.ButtonParts.PART_Minimize.ToString());
            button.IsHitTestVisible = false;
            button.Opacity = 0;
    
            // hides close button
            button = (Button)DevExpress.Xpf.Core.Native.LayoutHelper.FindElementByName(this, DXWindow.ButtonParts.PART_CloseButton.ToString());
            button.IsHitTestVisible = false;
            button.Opacity = 0;
        } 
    }
    

提交回复
热议问题