2

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?
Thomas
  • 4,030
  • 4
  • 40
  • 79
  • Can you read Chinese? I write some about connect to two page and some introduce about MVVM in this [post](http://lindexi.oschina.io/lindexi/post/win10-uwp-MVVM%E5%85%A5%E9%97%A8/).The good way to connect two page is use MVVMLight,see: http://www.mvvmlight.net/ – lindexi Feb 16 '17 at 06:15

2 Answers2

2

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;
    }
Community
  • 1
  • 1
Mamoru Satoh
  • 2,670
  • 23
  • 23
  • 1
    Looking at the UWP samples, MultiView & Projection look very similar, where you create a new frame with a new view. I'll probably need the SecondaryViewsHelper to control the projection as well since it's its own view instance, right? – Thomas Feb 16 '17 at 08:15
  • Ah, you're right. I've misunderstood about the projection model. I'll modify it. – Mamoru Satoh Feb 16 '17 at 08:21
  • Could you give an example, how you would use the SecondaryViewsHelper for calling methods in other views? Specifically, I want to pass a scroll event to the second view. – Thomas Feb 16 '17 at 12:41
1

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

enter image description here

Thomas
  • 4,030
  • 4
  • 40
  • 79