2013-06-24 4 views
1

Я создаю приложение для магазина Windows 8. В моем приложении у меня есть Bottom AppBar, из которого я открываю новую страницу, на которой я показываю сетку, показанную в примере Grid App.But, к сожалению, моя страница не является (видимо, видна только верхняя кнопка с именем, а остальная часть части, включая «Сетка», не видна). Я не знаю почему? Я пробовал почти все, пожалуйста, помогите мне. Я добавил код для справки.Grid View не отображается

<common:LayoutAwarePage 
x:Name="pageRoot" 
x:Class="MyApp.Reader" 
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:MyApp"  
xmlns:data="using:MyApp.Data" 
xmlns:common="using:MyApp.Common" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d"> 

<Page.Resources> 

    <!-- TODO: Delete this line if the key AppName is declared in App.xaml --> 
    <x:String x:Key="AppName">My Application</x:String> 

    <CollectionViewSource 
     x:Name="groupedItemsViewSource" 
     Source="{Binding Groups}" 
     IsSourceGrouped="true" 
     ItemsPath="TopItems" 
     d:Source="{Binding AllGroups, Source={d:DesignInstance Type=data:SampleDataSource, IsDesignTimeCreatable=True}}"/> 
</Page.Resources> 

<!-- 
    This grid acts as a root panel for the page that defines two rows: 
    * Row 0 contains the back button and page title 
    * Row 1 contains the rest of the page layout 
--> 
<Grid Style="{StaticResource LayoutRootStyle}"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="140"/> 
     <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 
    <Grid.Background> 
     <ImageBrush ImageSource="Assets/background.jpg"/> 
    </Grid.Background> 

    <GridView 
     x:Name="itemGridView" 
     AutomationProperties.AutomationId="ItemGridView" 
     AutomationProperties.Name="Grouped Items" 
     Grid.RowSpan="2" 
     Padding="116,137,40,46" 
     ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}" 
     ItemTemplate="{StaticResource Standard250x80ItemTemplate}" 
     SelectionMode="None" 
     IsSwipeEnabled="false" > 

     <GridView.ItemsPanel> 
      <ItemsPanelTemplate> 
       <VirtualizingStackPanel Orientation="Horizontal"/> 
      </ItemsPanelTemplate> 
     </GridView.ItemsPanel> 
     <GridView.GroupStyle> 
      <GroupStyle> 
       <GroupStyle.HeaderTemplate> 
        <DataTemplate> 
         <Grid Margin="1,0,0,6"> 
          <Button 
           AutomationProperties.Name="Group Title" 
           Style="{StaticResource TextPrimaryButtonStyle}" > 
           <StackPanel Orientation="Horizontal"> 
            <TextBlock Text="{Binding Title}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" /> 
            <TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/> 
           </StackPanel> 
          </Button> 
         </Grid> 
        </DataTemplate> 
       </GroupStyle.HeaderTemplate> 
       <GroupStyle.Panel> 
        <ItemsPanelTemplate> 
         <VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,80,0"/> 
        </ItemsPanelTemplate> 
       </GroupStyle.Panel> 
      </GroupStyle> 
     </GridView.GroupStyle> 
    </GridView> 

    <ListView 
     x:Name="itemListView" 
     AutomationProperties.AutomationId="ItemListView" 
     AutomationProperties.Name="Grouped Items" 
     Grid.Row="1" 
     Visibility="Collapsed" 
     Margin="0,-10,0,0" 
     Padding="10,0,0,60" 
     ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}" 
     ItemTemplate="{StaticResource Standard80ItemTemplate}" 
     SelectionMode="None" 
     IsSwipeEnabled="false" 
     IsItemClickEnabled="True"> 

     <ListView.GroupStyle> 
      <GroupStyle> 
       <GroupStyle.HeaderTemplate> 
        <DataTemplate> 
         <Grid Margin="7,7,0,0"> 
          <Button 
           AutomationProperties.Name="Group Title" 
           Style="{StaticResource TextPrimaryButtonStyle}"> 
           <StackPanel Orientation="Horizontal"> 
            <TextBlock Text="{Binding Title}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" /> 
            <TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/> 
           </StackPanel> 
          </Button> 
         </Grid> 
        </DataTemplate> 
       </GroupStyle.HeaderTemplate> 
      </GroupStyle> 
     </ListView.GroupStyle> 
    </ListView> 

    <!-- Back button and page title --> 
    <Grid> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="Auto"/> 
      <ColumnDefinition Width="*"/> 
     </Grid.ColumnDefinitions> 
     <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}" VerticalAlignment="Center"/>   
     <TextBlock Grid.Column="1" Style="{StaticResource PageHeaderTextStyle}" Text="{StaticResource AppName}" TextWrapping="Wrap" VerticalAlignment="Center" Height="40" Width="Auto"/> 
    </Grid> 
    <VisualStateManager.VisualStateGroups> 

     <VisualStateGroup x:Name="ApplicationViewStates"> 
      <VisualState x:Name="FullScreenLandscape"/> 
      <VisualState x:Name="Filled"/> 

      <VisualState x:Name="FullScreenPortrait"> 
       <Storyboard> 
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style"> 
         <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/> 
        </ObjectAnimationUsingKeyFrames> 
       </Storyboard> 
      </VisualState> 


      <VisualState x:Name="Snapped"> 
       <Storyboard> 
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style"> 
         <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/> 
        </ObjectAnimationUsingKeyFrames> 
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style"> 
         <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/> 
        </ObjectAnimationUsingKeyFrames> 
       </Storyboard> 
      </VisualState> 
     </VisualStateGroup> 
    </VisualStateManager.VisualStateGroups> 
</Grid> 

Это почти так же, как образец (новый project-> Сетка приложение XAML()). На AppBar кнопку мыши Я открываю новую страницу в

private void Next_Click_1(object sender, RoutedEventArgs e) 
{ 
    this.Frame.Navigate(typeof(Reader), "AllGroups"); 
} 

В то время как на странице, который должен быть показан я добавил

protected override void OnNavigatedTo(NavigationEventArgs e) 
{ 
    var sampleDataGroups = SampleDataSource.GetGroups(e.Parameter.ToString()); 
    this.DefaultViewModel["Groups"] = sampleDataGroups; 
} 

Остальной код почти так же от sample.I утра получение данных по 'sampleDataGroups' правильно, но не знаю, почему моя страница не видна с помощью Grid?

ответ

1

Okes Это происходит из-за предоставленного DataContext.

DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}" 

Так что я удалил это, чтобы получить работу, и ее работоспособность. Это связано с тем, что мы уже предоставлены. Связывание внутри, поэтому нет необходимости добавлять привязку к DefaultViewModel