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.
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();
}
Thanks in advance.
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: