سؤال

I have a xaml page:

<Page x:Class="DailyStyleW8.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="using:DailyStyleW8"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:converters="using:DataTypes"
      mc:Ignorable="d">

  <Page.Resources>
    <converters:PortableImageConverter x:Key="ImageConverter" />
  </Page.Resources>

  <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <Grid>
      <ProgressBar x:Name="loadingViewer"
                   IsIndeterminate="True"
                   Height="20" />
      <FlipView x:Name="displayViewer"
                ItemsSource="{Binding}"
                Visibility="Collapsed">
        <FlipView.ItemTemplate>
          <DataTemplate>
            <Grid>
              <Image Source="{Binding Image,Converter={StaticResource ImageConverter}}" />
              <TextBlock Text="{Binding Name}" />
            </Grid>
          </DataTemplate>
        </FlipView.ItemTemplate>
      </FlipView>
    </Grid>
  </Grid>
</Page>

and in the code behind file:

using DailyStyleApp;
using PortableAPI;
using System;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace DailyStyleW8
{
    /// <summary>
    /// Display a list of recent updates to the user
    /// </summary>
    public sealed partial class MainPage : Page
    {
        Controller controller = new Controller();

        public MainPage()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            LoadContent();
        }

        private async void LoadContent()
        {
            var viewModel = await controller.GetMultiDayAsync(DateTime.Now, PortableAPIProvider.Storage.ReadFromSettings<int>("CacheDuration", 7));
            displayViewer.ItemsSource = viewModel.Items;
            displayViewer.Visibility = Windows.UI.Xaml.Visibility.Visible;
            loadingViewer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
        }
    }
}

Now when I run the code the LoadContent function is called correctly and the viewModel object is formed correctly. If I comment out the line displayViewer.ItemsSource = viewModel.Items; the ProgressBar visibility is changed as you would expect.

When that line is left in and stepped through all 4 lines inside the LoadContent method are run, however the FlipView is not updated with the new items and the ProgressBar visibility is not changed. viewModel.Items is of type List<T>.

I am even sure really what to be searching for here. I am guessing it's something wrong with the XAML and my binding?

هل كانت مفيدة؟

المحلول

The issue related to this question was actually to do with another section of code in the application. Elsewhere I had a series of async / await calls that were locking up the UI thread.

This prevented the scheduler from ever triggering the callbacks for the async. In short solution to the problem: Never call await on something that is called from the UI thread (and not via another async call).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top