Wpf 单击按钮时,对话框应显示在前面
我用的是棱镜5。要显示对话框,我使用InteractionRequest。IsModel属性被设置为False,所以当我单击主窗口(从那里引发对话框)时,对话框进入后台。现在我试图实现的是,当我再次单击按钮时,对话框应该再次出现在前面 以下是我的自定义PopupWindowAction类:Wpf 单击按钮时,对话框应显示在前面,wpf,prism,Wpf,Prism,我用的是棱镜5。要显示对话框,我使用InteractionRequest。IsModel属性被设置为False,所以当我单击主窗口(从那里引发对话框)时,对话框进入后台。现在我试图实现的是,当我再次单击按钮时,对话框应该再次出现在前面 以下是我的自定义PopupWindowAction类: public class CustomDialogWindow : PopupWindowAction { private Window window; protected override
public class CustomDialogWindow : PopupWindowAction
{
private Window window;
protected override Window GetWindow(INotification notification) {
window = base.GetWindow(notification);
return window;
}
public static readonly DependencyProperty SetFocusProperty =
DependencyProperty.Register("SetFocus", typeof(bool),
typeof(CustomDialogWindow), null);
public bool SetFocus {
get { return (bool)GetValue(SetFocusProperty); }
set {
if (value) {
if (window != null) {
window.Activate();
window.Focus();
}
}
SetValue(SetFocusProperty, value);
}
}
}
下面是我的XMAL端配置:
<prism:InteractionRequestTrigger SourceObject="{Binding ContainerMoveSummaryRequest, Mode=OneWay}">
<popout:CustomDialogWindow x:Name="ContentSummaryGridAction"
IsModal="False" SetFocus="{Binding SetFocusOnContainerMoveSummary,Mode=TwoWay}">
<popout:CustomDialogWindow.WindowContent>
<dialogs:ContainerMoveSummaryDialog />
</popout:CustomDialogWindow.WindowContent>
</popout:CustomDialogWindow>
</prism:InteractionRequestTrigger>
问题是,即使绑定是双向的,在更改SetFocusOnContainerMoveSummary
时,SetFocus
也没有得到更改
请让我知道任何解决办法
问题是,即使绑定是双向的,在更改SetFocusOnContainerMoveSummary
时,SetFocus
也不会被调用
这是预期的行为,框架绕过helper属性并直接使用dependency属性
您需要在dependency属性上设置回调,然后从那里开始:
public static readonly DependencyProperty SetFocusProperty =
DependencyProperty.Register(nameof(SetFocus),
typeof(bool),
typeof(CustomDialogWindow),
new PropertyMetaData( default(bool), OnSetFocusChanged);
private static void OnSetFocusChanged( DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs )
{
// get the window from dependencyObject (= the CustomDialogWindow instance) and call SetFocus
}
您可以尝试为对话框调用一个焦点方法,这将使它出现在最前面。如何?装订在哪里?复印件