benruehl / adonis-ui

Lightweight UI toolkit for WPF applications offering classic but enhanced windows visuals
https://benruehl.github.io/adonis-ui/
MIT License
1.7k stars 143 forks source link

Add support for disabling title bar buttons #120

Closed micah686 closed 3 years ago

micah686 commented 3 years ago

Is your feature request related to a problem? Please describe. No, it's not related to an issue

Describe the solution you'd like I would like an IsEnabled/Enabled Property for the Titlebar close, maximize, and minimize buttons. That would be useful if you needed to disable the close buttons while an operation is running

benruehl commented 3 years ago

The window buttons are already exposed on AdonisWindow so you could access them in your window's code-behind:

public MainWindow()
{
    InitializeComponent();

    Loaded += (s, e) =>
    {
        MinimizeButton.IsEnabled = false;
        MaximizeRestoreButton.IsEnabled = false;
        CloseButton.IsEnabled = false;
    };
}

Be aware that this does not prevent the user from closing the window on other ways like Alt+F4.

micah686 commented 3 years ago

Unfortunately, I need xaml binding, because the MVVM toolkit I'm using(Stylet), has you completely remove the code behind, so I can't use the code behind options.

benruehl commented 3 years ago

If Stylet requires you to remove your code-behind file, there must be another way to do event handling. I don't know Stylet but from looking at their docs, I think Actions look promising. Additionally, it seems like deleting the code-behind is optional (source).

You could also implement a custom behavior or an attached property for your window that sets the properties.

I guess what you wish for are properties on the window like IsCloseButtonEnabled. But imagine multiple people who each want to control a specific property of the buttons. It would become kind of messy in AdonisWindow really fast. Especially because each property would need to exist 3 times (because 3 buttons).

If you really like to go this way, you could also create your own subclass of AdonisWindow and create those properties yourself. You could create 2-way-bindings in code that map the internal IsEnabled properties of all 3 buttons to your own exposed properties.

benruehl commented 3 years ago

Closing this because it seems to be resolved.