Search code examples
c#wpfwindowsshowdialogmouse-cursor

WPF ShowDialog - change parent window's cursor


I have a little problem when opening a window by ShowDialog.

I have a main window which when the application is loading data from the data source, opens another small window as a dialog to show the loading progress.

When the small loading progress window opens up, the cursor of that window is set to a custom Busy cursor and I am trying to set the main window's cursor to be the same as in the small loading window, but no matter what I try, it doesn't work.

I know that when opening a window as a dialog with ShowDialog, the opening window's cursor is set to be the normal default cursor (when hovering over your dialog, you have your selected cursor, but when hovering over the main window while the dialog is open, the cursor is set to the default cursor [arrow]). I am trying to make my app show the same custom Busy cursor when the loading dialog is open, while hovering over the dialog itself and over the window that has opened the dialog, while preventing the user from accessing the main window's content, preventing from minimizing the small loading window and preventing from letting the small loading window be under the main window.

  1. Is there any way of doing so (as stated above) while using ShowDialog or something similar to ShowDialog?
  2. Is there way of changing the default cursor of the ENTIRE application (for example a custom arrow cursor instead of the one windows has by default)?
  3. Is there any way of opening a dialog, setting it's cursor to be a custom Busy cursor and by that setting that cursor to be present while hovering over any part of the application?

My codes:

private void Window_ContentRendered(object sender, EventArgs e)
        {
            Mouse.OverrideCursor = new Cursor(System.IO.Path.GetFullPath(System.IO.Path.Combine(strCurrentDir, @"..\..\")) + @"Cursors\busy.ani");
            //this.Cursor = new Cursor(System.IO.Path.GetFullPath(System.IO.Path.Combine(strCurrentDir, @"..\..\")) + @"Cursors\busy.ani");
            //Mouse.OverrideCursor = Cursors.Wait;

            bwReload = new BackgroundWorker();
            bwReload.WorkerReportsProgress = true;
            bwReload.DoWork += (sender_bw, e_bw) =>
            {
                new Thread(() =>
                {
                    Application.Current.Dispatcher.Invoke(() => 
                    {
                        ProgressBarWindow pbwLoadWindow = new ProgressBarWindow("Loading...", this);
                        pbwLoadWindow.ShowInTaskbar = false;
                        pbwLoadWindow.Owner = this;
                        pbwLoadWindow.Cursor = new Cursor(System.IO.Path.GetFullPath(System.IO.Path.Combine(strCurrentDir, @"..\..\")) + @"Cursors\busy.ani");
                        pbwLoadWindow.ShowDialog();
                    });
                }).Start();

                ReloadA();
                ReloadB();
            };
            bwReload.RunWorkerCompleted += (sender_bw, e_bw) => btnViewDashboard_Click(this, null);

            bwReload.RunWorkerAsync();
        }

While hovering over the small loading window.

While hovering over the main window, while it is still loading.

Thanks in advance.


Solution

  • SOLVED

    It is simple.

    All you need to do is go to the dialog window's xaml and fit the window like that, that it will cover the entire main window.

    Code:

    <Window x:Class="PlGui.ProgressBarWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:PlGui"
            mc:Ignorable="d" Height="600" Width="1025"
            ResizeMode="NoResize" WindowStartupLocation="CenterScreen"
            WindowStyle="None" AllowsTransparency="True">
    
        <Window.Background>
            <SolidColorBrush Opacity="0.01" Color="White"/>
        </Window.Background>
    
        <Grid Height="100"
              Width="350"
              HorizontalAlignment="Center"
              VerticalAlignment="Center"
              Background="#7f8c8d">
             ......
        </Grid>
    
    </Window>
    

    The results:

    Hovering over the dialog window

    Hovering over the main window while the dialog window is open