如何解决WPF ShowDialog - 更改父窗口的光标
我在通过 ShowDialog 打开窗口时遇到了一个小问题。
我有一个主窗口,当应用程序从数据源加载数据时,它会打开另一个小窗口作为对话框来显示加载进度。
当小加载进度窗口打开时,该窗口的光标设置为自定义忙碌光标,我试图将主窗口的光标设置为与小加载窗口中的光标相同,但无论如何我试试,没用。
我知道当使用 ShowDialog 打开一个窗口作为对话框时,打开窗口的光标设置为正常的默认光标(当悬停在对话框上时,你有你选择的光标,但是当悬停在主窗口上时对话框打开,光标设置为默认光标 [箭头])。 我试图让我的应用程序在加载对话框打开时显示相同的自定义忙碌光标,同时将鼠标悬停在对话框本身和打开对话框的窗口上,同时防止用户访问主窗口的内容,防止最小化小加载窗口,防止小加载窗口在主窗口下方。
- 在使用 ShowDialog 或类似 ShowDialog 的东西时,有没有办法做到这一点(如上所述)?
- 是否可以更改 ENTIRE 应用程序的默认光标(例如自定义箭头光标而不是默认情况下的一个窗口)?
- 有什么方法可以打开对话框,将其光标设置为自定义忙碌光标,然后将该光标设置为在悬停在应用程序的任何部分上时出现?
我的代码:
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();
}
提前致谢。
解决方法
已解决
很简单。
您需要做的就是转到对话框窗口的 xaml 并像这样调整窗口,使其覆盖整个主窗口。
代码:
<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>
结果:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。