繁体   English   中英

在Windows应用商店中更新GridView

[英]Update GridView in windows store

我正在使用C#/ XAML为Windows商店(MVVM模式)开发应用程序。 当前视图显示类别及其课程列表,如下所示。

<CollectionViewSource x:Name="groupedItemsViewSource"
                      Source="{Binding Path=ListCourses}"
                      IsSourceGrouped="true"
                      ItemsPath="Courses" />

GridView中的课程列表:

<GridView
   x:Name="itemGridView"
   AutomationProperties.AutomationId="ItemGridView"
   AutomationProperties.Name="Grouped Items"
   Grid.RowSpan="2"
   Padding="116,35,40,46"
   SelectionMode="Single"
   ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
   ItemTemplate="{StaticResource ListCourseItemTemplate}"
   SelectedItem="{Binding SelectedItem, Mode=TwoWay}"         
   IsSwipeEnabled="false"
   IsItemClickEnabled="True">      
     <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"
                                 Foreground="{StaticResource WShopperAccentTextBrush}"
                                 Style="{StaticResource TextPrimaryButtonStyle}">
                                 <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Name}" 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>

班级分类:

public Category()
{

}
public int Id { get; set; }

public string Name { get; set; }


public IEnumerable<Course> Courses { get; set; }

在我的视图模型中,-ListCourses属性如下所示:

public ObservableCollection<Category> ListCourses
{
    get { return _listCourses; }
    private set { SetProperty(ref _listCourses, value); }
}

我的问题是:当我从列表中删除一个课程(从gridView中删除项目)时,gridView不会更新并显示ListCourses属性中的当前数据?

删除功能:

     var category = ListCourses.FirstOrDefault(cat => cat.Id == SelectedItem.CategoryId);
        category.Courses.Remove(SelectedItem);
        OnPropertyChanged("ListCourses");

有任何想法吗??

category.Courses需要是ObservableCollection

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM