如果您不熟悉Ookii.Dialogs,,我建议您先使用看这个网页。它是开源的,您可以在那里找到源代码、编译的二进制文件、文档和示例应用程序。
在我的应用程序中,我使用Ookii.Dialogs.Wpf.ProgressDialog to ShowDialog(这)--一个对文件进行一些处理的进度对话框(这始终是应用程序的主窗口)。正如预期的那样,进度对话框在实际可见之前大约需要一秒钟的时间(即使它已经在处理我的文件)。
在进度对话框的DoWork线程中,我还检查输出文件是否已经存在,并询问用户是覆盖每个文件还是跳过输出。我使用Ookii.Dialogs.Wpf.TaskDialog到ShowDialog(这)一个“任务对话框与命令链接”(类似于这),并问用户覆盖问题--除非操作系统不支持它,否则我回到了常规的MessageBox (问题也适用于消息框以及)。
当我的应用程序在进度对话框的DoWork线程的开头找到一个现有文件时,就会出现这个问题。当任务对话框出现时,询问用户是否要覆盖: 预期行为:任务对话框必须保持在顶部。当进度对话框出现时(在1s延迟之后),它必须出现在任务对话框后面。 实际行为:任务对话框不停留在顶部。当进度对话框出现在1s延迟后),它将出现在任务对话框的顶部。
当进度对话框已经可见时,实际的行为不会发生在后续的覆盖请求中。任务对话框正确地出现在后续对话框的顶部,尽管用户可以来回切换两个对话框(只是不能从其中任何一个切换到主窗口)。
我在找这个:
我是,而不是,我在寻找以下内容:
发布于 2012-08-18 18:44:37
我知道这可能有点晚了,但我只是在我自己的程序中提前解决了一个类似的问题,这让我想起了这个问题。我对任务对话窗口标题属性使用了windows FindWindowEx API函数来查找对话窗口句柄,然后使用我自己的类使之成为一个Iwin32Window,然后它可以用作消息框或任务对话的父类。适当的代码如下(VB.NET)
'allows us to use the handle as a window
class window
Implements IWin32Window
private _handle
public sub new(handle as intptr)
_handle = handle
end sub
Public ReadOnly Property Handle As System.IntPtr Implements System.Windows.Forms.IWin32Window.Handle
Get
Return _h
End Get
End Property
end class
'Declare the needed DLL import
class NativeMethods
<DllImport("user32.dll", SetLastError:=True, ThrowOnUnmappableChar:=True, CharSet:=CharSet.Unicode, bestFitMapping:=False)>
Public Shared Function FindWindowEx(hwndParent As IntPtr, hwndChildAfter As IntPtr, lpszClass As String, lpszWindow As String) As IntPtr
End Function
end class
'Make sure you've set a window title when you run your task
sub runTask()
dim myDlg as Ookii.Dialogs.ProgressDialog
'Do what you need to here
myDlg.WindowTitle = "make sure you set a title"
end sub
sub myTask(sender as object, e As System.ComponentModel.DoWorkEventArgs)
'Checks and balances here
if fileExists then
'this is the dialog that's running our task
Dim dlg As Ookii.Dialogs.ProgressDialog = DirectCast(sender, Ookii.Dialogs.ProgressDialog)
'Find the window handle
Dim dlgHandle As IntPtr = NativeMethods.FindWindowEx(IntPtr.Zero, IntPtr.Zero, Nothing, dlg.WindowTitle)
'make it an Iwin32Window
dim dlgWindow as new window(dlgHandle)
'That can then be used as a parent for the message box or the task dialog
MessageBox.Show(dlgWindow,"The file exists, overwrite?")
end if
end sub
我并不擅长评论我的代码或让我的解释被理解,所以如果你对发生了什么有任何疑问,我会尽力帮助你。
发布于 2014-07-23 13:00:28
今天我读了这个问题,找到了一个解决办法。为TaskDialog试了一下,这也很管用。没有尝试与其他对话框。我编写了一个DialogControler来处理MVVM。这个DialogControlar有一个名为'Owner‘的属性,它包含WPF-主窗口。然后,我使用它来调用(在我的例子中,我是来自视图模型中的一个后台线程),并在ShowDialog中设置它。
我的守则:
using (var dialog = new Ookii.Dialogs.Wpf.TaskDialog())
{
dialog.WindowTitle = "My title";
dialog.MainInstruction = "My text";
var okButton = new Ookii.Dialogs.Wpf.TaskDialogButton(Ookii.Dialogs.Wpf.ButtonType.Ok);
dialog.Buttons.Add(okButton);
Owner.Dispatcher.Invoke(new Action(() => dialog.ShowDialog(Owner)));
}
有了这个,我就有了一个最上面的窗户。
https://stackoverflow.com/questions/9595269
复制相似问题