2014-10-06 75 views
0

这里是一款Windows Phone 8.1我目前的应用流程:Page.BottomAppBar没有被刷新为NavigationCacheMode启用

  • 我有一个枢轴和BottomAppBar
  • 枢纽项目内容是使用一个填充的MainPage在以上代码的MainPage:
protected override void OnNavigatedTo(NavigationEventArgs e) 
    { 
     if (RootPivot.Items == null) return; 
     RootPivot_OnPivotItemLoaded(RootPivot, new PivotItemEventArgs { Item = RootPivot.Items[RootPivot.SelectedIndex] as PivotItem }); 
    } 

    private void RootPivot_OnPivotItemLoaded(Pivot sender, PivotItemEventArgs args) 
    { 
     if (args.Item.Content == null) args.Item.Content = CreateUserControlForPivotItem((string)args.Item.Header, sender); 

     var content = args.Item.Content as UserControl; 
     if (content == null || content.DataContext == null) 
     { 
      BottomAppBar.DataContext = null; 
      return; 
     } 

     BottomAppBar.DataContext = null; 
     BottomAppBar.DataContext = content.DataContext; 

     var viewModel = content.DataContext as IRefreshableViewModel; 
     if (viewModel != null) viewModel.Refresh(); 
    } 

    private static UserControl CreateUserControlForPivotItem(string pivotItemHeader, Pivot pivot) 
    { 
     UserControl item = null; 
     switch (pivotItemHeader) 
     { 
      case "Appointments": 
       item = new AppointmentsPivotItem(); 
       break; 

      case "Profile": 
       item = new ProfilePivotItem(); 
       break; 
     } 

     return item; 
    } 

各用户控件具有一个ViewModel作为DataContext的,它负责处理该BottomAppBar:

<Page.BottomAppBar> 
    <CommandBar x:Name="BottomAppBar" Foreground="#FFFEFEFE" Background="{StaticResource BlueColorBrush}" Visibility="{Binding Converter={StaticResource BooleanToVisibilityConverter}, Path=RequiresBottomAppBar, FallbackValue=Collapsed}"> 
     <CommandBar.PrimaryCommands> 
      <AppBarButton Icon="Add" Label="{Binding AppBarButtonAdd}" Command="{Binding AppBarButtonAddCommand}" Visibility="{Binding Converter={StaticResource BooleanToVisibilityConverter}, Path=RequiresAppBarButtonAdd, FallbackValue=Collapsed}">   </AppBarButton> 
      <AppBarButton Icon="Find" Label="{Binding AppBarButtonFind}" Command="{Binding AppBarButtonFindCommand}" Visibility="{Binding Converter={StaticResource BooleanToVisibilityConverter}, Path=RequiresAppBarButtonFind, FallbackValue=Collapsed}"></AppBarButton> 
     </CommandBar.PrimaryCommands> 
    </CommandBar> 
</Page.BottomAppBar> 

关于AppointmentsPivotItem我有一个ListView,当我尝试从项目详细信息页面导航回列表时,问题就开始了。 MainPage有NavigationCacheMode="Enabled",并且在导航回来时AppBar的绑定正在被调用,但是,直到我导航通过数据透视项目时,它才会出现。

你能推荐一个解决办法吗? 在此先感谢。

回答

0

最后,在一天后,我突然想到了一个解决方案,可以解决问题。 不知何故,在设置DataContext之前调用BottomAppBar.UpdateLayout()将强制条形图相应地重新绘制到绑定。

希望这会帮助别人。