简体   繁体   中英

UWP: Control second window from main window

Inside a UWP app I want to control some animations on a second screen from my main app window. As far as I can tell I have two options: create a second Window or use the projection feature .

My questions are:

  • Which option would make more sense / would be easier to implement in this scenario?
  • How can I react to events from my main window on my second screen?

About Q2:

There are some way to interact with multi thread model. If you write your app based on the MultiView sample, you can use the SecondaryViewsHelper to call method on the another pages, etc. Or, you can call the LaunchUriAsync from each pages. If you regist your app as protocol handler, you can receive the call at OnLaunched method. This is common for both Projection and Multi-View.

This SO page also helps you :)

Multiple instances of a Windows Universal App (Windows 10)

Edited: Sample - It's used on my uwp app - added.

    // This is a method of Application class "F10Client".
    // SecondaryViews is a member of this class.
    // In my app, this method is called when the app resumes.
    public async Task<bool> TogglePrivateMaskForAllPages(bool isMask)
    {
        bool retVal = true;
        if (null != ((F10Client)F10Client.Current).SecondaryViews && 0 < ((F10Client)F10Client.Current).SecondaryViews.Count)
        {
            foreach (var view in ((F10Client)F10Client.Current).SecondaryViews)
            {
                // You should use dispatcher to call the page method.
                await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    var thePage = (ImagePage)((Frame)Window.Current.Content).Content;
                    // calling the method.
                    thePage.TogglePrivacyMask(isMask);
                });
            }
        }
        return retVal;
    }

For my first question, the Guidelines for projection manager helped me choose the right way to go:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM