单击按钮时对话框应该出现在前面

Dialog should come to front on button click

我正在使用 Prism 5。为了显示对话框,我正在使用 InteractionRequest。 IsModel 属性 设置为 False,因此当我单击主要 window(从引发对话框的位置)时,对话框进入后台。现在我要实现的是,当我再次单击按钮时,对话框应该再次出现。

这是我的自定义 PopupWindowAction 类:

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 没有更改。

请告诉我任何解决方案。

The problem is even though binding is two way, on changing SetFocusOnContainerMoveSummary, SetFocus is not getting called

这是预期的行为,框架绕过助手 属性 并直接使用依赖项 属性。

您需要在依赖项 属性 上设置回调,然后从那里开始:

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
}