How to disable the double-click to maximize a RadWindow

1 Answer 45 Views
Window
minh
Top achievements
Rank 1
Iron
Iron
minh asked on 15 Oct 2021, 11:01 AM | edited on 19 Oct 2021, 10:38 AM

Hello,

I would disable to double-click event to maximize a RadWindow.

I hope you can help to realize that.

 

Many thanks

1 Answer, 1 is accepted

Sort by
0
Accepted
Stenly
Telerik team
answered on 19 Oct 2021, 03:09 PM

Hello Minh,

Currently, the RadWindow control does not provide an API to achieve the wanted result, because this behavior comes from the native Window class, and it will be quite hard to modify. However, you could use the approach specified in this article. More specifically, subscribe to the HostCreated event of the Window control, and inside of it, set the SourceInitialized event of the HostWindow property provided by the HostWindowCreatedEventArgs event arguments. And finally, add the additional code from the provided article. MainWindow partial class should look as follows:

public partial class MainWindow : RadWindow
{
    public MainWindow()
    {
        InitializeComponent();

        this.HostCreated += MainWindow_HostCreated;
    }
	
    [DllImport("user32.dll")]
    private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
    [DllImport("user32.dll")]
    private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

    private const int GWL_STYLE = -16;
    private const int WS_MAXIMIZEBOX = 0x10000;
	
    private void MainWindow_HostCreated(object sender, HostWindowCreatedEventArgs e)
    {
        e.HostWindow.SourceInitialized += Window_SourceInitialized;
    }

    private void Window_SourceInitialized(object sender, EventArgs e)
    {
        IntPtr hwnd = new WindowInteropHelper((Window)sender).Handle;
        var value = GetWindowLong(hwnd, GWL_STYLE);
        SetWindowLong(hwnd, GWL_STYLE, (int)(value & ~WS_MAXIMIZEBOX));
    }
}

This will prevent the window from maximizing on double-click but it will retain its ability to drag and resize, and also, to get maximized from the maximized button.

That said, I have attached a sample project that implements this approach, so, could you give it a try? Also, if this is not the expected behavior, could provide a bit more information about what the expected result is?

Regards,
Stenly
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

minh
Top achievements
Rank 1
Iron
Iron
commented on 20 Oct 2021, 02:19 AM

Hello Stenly,

Thank you very much! Your solution work like a charm.

Thank again and hope you have a great day

Tags
Window
Asked by
minh
Top achievements
Rank 1
Iron
Iron
Answers by
Stenly
Telerik team
Share this question
or