C# 在windows应用商店中更新GridView
我正在使用C#/XAML为windows应用商店开发一个应用程序(MVVM模式)。 当前视图显示类别及其课程列表,如下所示C# 在windows应用商店中更新GridView,c#,xaml,data-binding,windows-store-apps,C#,Xaml,Data Binding,Windows Store Apps,我正在使用C#/XAML为windows应用商店开发一个应用程序(MVVM模式)。 当前视图显示类别及其课程列表,如下所示 <CollectionViewSource x:Name="groupedItemsViewSource" Source="{Binding Path=ListCourses}" IsSourceGrouped="true" ItemsP
<CollectionViewSource x:Name="groupedItemsViewSource"
Source="{Binding Path=ListCourses}"
IsSourceGrouped="true"
ItemsPath="Courses" />
有什么想法吗
类别。课程
也需要是一个可观察集合
。列出课程。移除(类别)将移除整个类别(连同课程列表,我不希望发生的事情!!),我需要从类别中移除课程,如何解决?
<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; }
public ObservableCollection<Category> ListCourses
{
get { return _listCourses; }
private set { SetProperty(ref _listCourses, value); }
}
var category = ListCourses.FirstOrDefault(cat => cat.Id == SelectedItem.CategoryId);
category.Courses.Remove(SelectedItem);
OnPropertyChanged("ListCourses");