The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
[RS6:1903][BUG] CaptureElement turns black when loosing focus inside contentdialog RRS feed

  • Question

  • Hi,

    I have a weird bug where the video of a CaptureElement suddenly disappears when moving the courser outside the contentdialog focus. I made a minimum testcase, so you can reproduce the issue

    How my UI looks like:

    * A (Main) Page with a button that opens a contentcontrol

    * The contentcontrol contains a pivot element

    * The pivot element has it itemssource binded to a viewmodel with a datatemplate

    The issue only occurs if:

    * The contentdialog was opened within the code. If you define in in xaml, everything is fine

    * The mouse cursor must be inside the contentdialog box while starting the video. If you move it outside the video turns black. If it was outside before the video started there is no problem (i've added a 1second delay in the sample to test this better)

    * The pivot contains an itemssource binded to a viewmodel. When using simple pivotitems there is no problem

    * The camera initialization happens when opening the dialog. I used the opened() event, but it could be done in the constructor as well (but bad practise). When initializing the camera with a button inside the contentdialog, the issue does not appear.

    A workaround:

    var dialog = new SettingsDialog();
    //(Grid) this.Content).Children.Add(dialog);
    await dialog.ShowAsync();

    The problem is, that the contentdialog does not belong to the UI element tree (as far as I understand). If you add it as a children, the bug does not appear. This might be also the reason why a contentdialog defined in xaml works fine. In my (larger) use case I must also pass some parameters, thatswhy this is not an option.

    Here is the sample code:

    https://github.com/AtosNicoS/CameraCrashTest



    Thursday, June 6, 2019 9:46 AM

All replies

  • Hi,

    I had reproduced the issued you said on build 18362. I will report this issue to the team to confirm this. There might be some time delay. Thank you for reporting this issue here. 

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 7, 2019 6:24 AM
  • Any progress yet?
    Wednesday, July 10, 2019 9:15 AM
  • Hi,

    Sorry for the delay. I want to share the response I got from the team with you here. 

    The issue occurs due to DataContextChanged. When the context changes via moving the mouse from the dialog over the MainPage, we are implicitly setting the media source using data binding. We are setting the source of the capture element to a source object that has not been fully configured causing the behavior of the capture element to render a black frame.

    If you don't want to use this line of code. 

    (Grid) this.Content).Children.Add(dialog);

    Another workaround could be to detect the change in data context in the view model and fully reinitialize just after the context change. like this:

    First, add DataContextChanged to the CaptureElement.

    <CaptureElement DataContextChanged="MyCaptureElement_DataContextChanged"  x:Name="MyCaptureElement" Stretch="Uniform" Source="{x:Bind MediaSource, Mode=OneWay}" Height="100"/>

    Removed the line from SettingsDialog_OnOpened so it isn’t calling Init anymore, then add MyCaptureElement_DataContextChanged. Implement the Init here instead of OnOpenend

    private async void SettingsDialog_OnOpened(ContentDialog sender, ContentDialogOpenedEventArgs args)
            {
                //await ViewModel.Categories.First().Init();
            }
    
            private async void MyCaptureElement_DataContextChanged(Windows.UI.Xaml.FrameworkElement sender, Windows.UI.Xaml.DataContextChangedEventArgs args)
            {
                Debug.WriteLine($"{nameof(MyCaptureElement_DataContextChanged)} triggered");
                // reinitialize source here
                await ViewModel.Categories.First().Init();
            }

    And the last thing is that MediaPlayerElement is the preferred way of doing this going forward if possible. 

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 22, 2019 2:52 AM
  • Hey Atos,
    There's also the MediaPlayerElement which supports this scenario at https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.mediaplayerelement

    -David Hollowell (MSFT) Please remember to click &amp;amp;quot;Mark as Answer&amp;amp;quot; the responses that resolved your issue, and to click &amp;amp;quot;Unmark as Answer&amp;amp;quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 25, 2019 6:42 PM