MAUI Popups, floating windows and containers

Piotr Kirklewski 1 Reputation point
2022-12-30T17:33:58.607+00:00

Hi there,
I need to get a popup window that is not bound to the main window but will allow me to determine where on the screen should it appear.
Requirements:

  1. I need to be able to decide the size, and location of the new window even if it's on another screen. (I'm already detecting all the screens so this is not an issue)
  2. I need to be able to operate / change values on the main window while the new window stays in place and receives commands from the changing values on the first window and displays them (Text for example)
  3. The new window should be able to display text but also it would be nice if it would be able to receive a background photo/video.

Is it at all possible in MAUI?
I know how to do that in Windows Forms but it looks like Windows Forms ls out of date and it soon will not be supported.
Also MAUI seems to have a nicer appearance out of the box. I really like it but I'm not sure if what I need to do is doable at the moment?

275116-zrzut-ekranu-2022-12-30-182953.jpg

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2023-01-02T06:51:08.793+00:00

    Hello,

    Is it at all possible in MAUI?

    Yes, it means Multi-window support in MAUI, you can see .NET MAUI windows - .NET MAUI | Microsoft Learn

    I need to be able to decide the size, and location of the new window even if it's on another screen.

    For the first issue, you can see the Position and size a Window section in the doc above, and set the X, Y, Width, and Height properties of the Window

    I need to be able to operate / change values on the main window while the new window stays in place and receives commands from the changing values on the first window and displays them (Text for example)

    You can call an Action to invoke the method in first window, or communicate with the viewmodel of the firstpage when you want to changing values in the page of second window, see Data binding and MVVM - .NET MAUI | Microsoft Learn

    The new window should be able to display text but also it would be nice if it would be able to receive a background photo/video

    You can get the Text(String) in first window, you should be able to pass the image in the same way.

    For more details, you can refer to the following code:
    Click the button to second window

    private void OnCounterClicked(object sender, EventArgs e)  
          {  
            Window secondWindow = new Window(new NewPage( FirstImage, "First window String to Second", ( string second) =>  
                {  
                      CounterBtn.Text = second;// get the second window page string and display  
            })) ;  
            var displayInfo = DeviceDisplay.Current.MainDisplayInfo;  
            secondWindow.X = (displayInfo.Width / displayInfo.Density - Window.Width) / 2;  
            secondWindow.Y = (displayInfo.Height / displayInfo.Density - Window.Height) / 2;  
                Application.Current.OpenWindow(secondWindow);  
        }  
    

    ctor of new page in second window

     public NewPage(Image firstImage, string firstTitle, Action<string> firstTitleAction)  
        {  
            InitializeComponent();  
            SecontTitleLabel.Text = firstTitle;//get the text from first window  
    
            // you can get the image from first window page  
    
            firstTitleAction("SecondTitle");// invoke the action to change the value in first windows,or you can invoke the action in the viewmodel  
                                            // there are three paramaters, you can replace these paramaters by a model, and you can also bind the value to the viewmodel of your page  
    
        }  
    

    Best Regards,
    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.