locked
Snapped view not working - screen goes black RRS feed

  • Question

  • My snapped view isn't working. I am using the same code for each page in the app. It works on GridView based pages. But on pages that I have built (no gridview) the snapped screen goes black when I snap it and doesn't show my list view. Has anyone else encountered this?

    Thanks

    Tuesday, December 4, 2012 6:35 PM

Answers

  • Thanks Jesse,

    I eventually found a workaround and I'll post it in case it helps others. It seems like the problem is created if I update the UI thread in the SizeChanged event handler, without async method.

    My original code handled screen changes that way:

    Window.Current.SizeChanged += OnSizeChanged;

     public void OnSizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs args)
     {

    if (currentState == ApplicationViewState.Snapped)

    {

        PageImageBackground.ImageSource = new BitmapImage(new Uri("ms-appx:/Picture1.jpg", UriKind.Absolute));
        Grid.SetColumn(ContentPanel, 0);
        Grid.SetColumnSpan(ContentPanel, 3);
    }
    else 
    {
        PageImageBackground.ImageSource = new BitmapImage(new Uri("ms-appx:/Picture2.jpg", UriKind.Absolute));
        Grid.SetColumn(ContentPanel, 1);
        Grid.SetColumnSpan(ContentPanel, 1);
    }

    }

    After putting the logic into async method, everything works:

    if (currentState == ApplicationViewState.Snapped)
    {
        await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
        {
            PageImageBackground.ImageSource =
                new BitmapImage(new Uri("ms-appx:/Picture1.jpg", UriKind.Absolute));
            Grid.SetColumn(ContentPanel, 0);
            Grid.SetColumnSpan(ContentPanel, 3);
        });
    }
    else 
    {
        await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
        {
            PageImageBackground.ImageSource =
                new BitmapImage(new Uri("ms-appx:/Picture2.jpg", UriKind.Absolute));
            Grid.SetColumn(ContentPanel, 1);
            Grid.SetColumnSpan(ContentPanel, 1);
        });
    }


    • Edited by Noam Behar Friday, December 7, 2012 2:44 PM
    • Marked as answer by Jesse Jiang Monday, December 10, 2012 10:32 AM
    Friday, December 7, 2012 2:42 PM

All replies

  • can post the xaml?


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Tuesday, December 4, 2012 6:48 PM
  • I just encountered this. It's even weirder - if I start the snap view navigation from my first page everything works great.

    But if I navigate to my second page, and activate the snap there, when I go back to the first page it gets black.

    Wednesday, December 5, 2012 8:30 PM
  • Hello,

    Would you please provide us the whole codes to reproduce this issue,

    You can upload your project to skydriver
    http://skydrive.live.com/

    It is not necessary that you send out the whole of your project. We just need a simplest sample to reproduce the problem. You can remove any confidential information or business details from it.

    If you don't want to upload the sample code, you can try to get the paid support from https://getsupport.microsoft.com/

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 6, 2012 8:50 AM
  • Thanks Jesse,

    I eventually found a workaround and I'll post it in case it helps others. It seems like the problem is created if I update the UI thread in the SizeChanged event handler, without async method.

    My original code handled screen changes that way:

    Window.Current.SizeChanged += OnSizeChanged;

     public void OnSizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs args)
     {

    if (currentState == ApplicationViewState.Snapped)

    {

        PageImageBackground.ImageSource = new BitmapImage(new Uri("ms-appx:/Picture1.jpg", UriKind.Absolute));
        Grid.SetColumn(ContentPanel, 0);
        Grid.SetColumnSpan(ContentPanel, 3);
    }
    else 
    {
        PageImageBackground.ImageSource = new BitmapImage(new Uri("ms-appx:/Picture2.jpg", UriKind.Absolute));
        Grid.SetColumn(ContentPanel, 1);
        Grid.SetColumnSpan(ContentPanel, 1);
    }

    }

    After putting the logic into async method, everything works:

    if (currentState == ApplicationViewState.Snapped)
    {
        await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
        {
            PageImageBackground.ImageSource =
                new BitmapImage(new Uri("ms-appx:/Picture1.jpg", UriKind.Absolute));
            Grid.SetColumn(ContentPanel, 0);
            Grid.SetColumnSpan(ContentPanel, 3);
        });
    }
    else 
    {
        await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
        {
            PageImageBackground.ImageSource =
                new BitmapImage(new Uri("ms-appx:/Picture2.jpg", UriKind.Absolute));
            Grid.SetColumn(ContentPanel, 1);
            Grid.SetColumnSpan(ContentPanel, 1);
        });
    }


    • Edited by Noam Behar Friday, December 7, 2012 2:44 PM
    • Marked as answer by Jesse Jiang Monday, December 10, 2012 10:32 AM
    Friday, December 7, 2012 2:42 PM