Home > Net >  How to set PopUpWindow to be on the same monitor as the application? (xaf)
How to set PopUpWindow to be on the same monitor as the application? (xaf)

Time:03-26

The user often moves my XAF Winforms app between monitors. However dialogs invoked by the PopUpWindowShowAction remain on the old monitor

This issue can be repeated with Dev Express's Main Demo ( although to debug it there I think I would need to get into the API code).

  1. Run Main Demo and move the application window to the second monitor.
  2. Select Users, right click a user and select Print Preview.

The Print Preview will appear on the first monitor.

In my similar case, my controller is

public partial class JobHeadFilterController : ViewController, IClassicController
{
    public JobHeadFilterController()
    {
        InitializeComponent();
        TargetViewNesting = Nesting.Root;
    }

    protected override void OnActivated()
    {
        base.OnActivated();
        popupWindowShowFilterAction.QuickAccess = true;
    }

    private void popupWindowShowFilterAction_CustomizePopupWindowParams(object sender,
        CustomizePopupWindowParamsEventArgs e)
    {
        var holder = new JobHeadFilterHolder();
        var npProvider = new NonPersistentObjectSpaceProvider(XafTypesInfo.Instance, null);
        var os = (NonPersistentObjectSpace)npProvider.CreateObjectSpace();
        var view = Application.CreateDetailView(os, holder);
        e.View = view;
    }

I have tried browsing the properties of CustomizePopupWindowParamsEventArgs but cant see what to set.

I can get the main form using

 var mainform = Application.MainWindow.Template as Form;

I think I need to do something like the following inside popupWindowShowFilterAction_CustomizePopupWindowParams

            var template = e.Application.MainWindow.Template;
            var window = new Window(Application, );  // having trouble figuring out the parameters
            e.DialogController.SetWindow(window);

Studying the docs

[Update]

I tried

var window = e.Application.MainWindow; e.DialogController.SetWindow(window);

but got an error

The 'DevExpress.ExpressApp.SystemModule.DialogController' controller is active.

I tried making my own dialog controller inheriting from the Dev DevExpress.ExpressApp.SystemModule.DialogController but got the same error.

CodePudding user response:

using System;
using System.Windows.Forms;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Templates;
using DevExpress.ExpressApp.Win.Templates;
namespace MyNameSpace;
 
public partial class CustomizeFormsWindowController : WindowController
{
    public CustomizeFormsWindowController()
    {
        InitializeComponent();
        TargetWindowType = WindowType.Child;
    }

    protected override void OnActivated()
    {
        base.OnActivated();
        Window.TemplateChanged  = WindowsTemplateChanged;
    }

    private void WindowsTemplateChanged(object sender, EventArgs e)
    {
        if (Window.Template is Form &&
            Window.Template is ISupportStoreSettings)
            ((ISupportStoreSettings)Window.Template).SettingsReloaded  =
                OnFormReadyForCustomizations;
    }

    private void OnFormReadyForCustomizations(object sender, EventArgs e)
    {
        if (sender is not PopupForm popupForm) return;
        var mainForm = Application.MainWindow.Template as Form;
        var X = mainForm.Location.X   (mainForm.Width - popupForm.Width) / 2;
        var Y = mainForm.Location.Y   (mainForm.Height - popupForm.Height) / 2;
        popupForm.SetDesktopLocation(X, Y);
    }

    protected override void OnDeactivated()
    {
        Window.TemplateChanged -= WindowsTemplateChanged;
        base.OnDeactivated();
    }
}
  • Related