I have a UWP app written in C#, where I need to open a second window.
Inside this second window, there is an element that I need to toggle the visibility of (in some cases).
Please find an MVCE here: https://github.com/cghersi/UWPExamples/tree/master/AppWindowAndVisibility
If you look into it, you will see an element m_searchGrid
which we can change the visibility (using method SwitchSearchBarVisibility()
)
To open a new window, I use the primitives AppWindow.TryCreateAsync
and ElementCompositionPreview.SetAppWindowContent
.
Now, the following procedure results in an Exception when calling ElementCompositionPreview.SetAppWindowContent
:
- Open a new window (in the app, click on the button "Open AppWindow")
- Change the visibility of an element in the newly opened window (in the app, in the new window that is opened, click on the button "Show/hide search bar")
- Close the second window
- Reopen again another window (in the app, re-click on the button "Open AppWindow")
From a code perspective, at step 4 I can see that the method ElementCompositionPreview.SetAppWindowContent
throws an Exception (see line 108 of MainPage.xaml.cs
, in the method ShowAsync()
).
Do you have any clue on what could be the cause?
Maybe I should configure the window or the element in different ways?
Thanks!!