WPF C#过滤具有许多条件的ListView项目

时间:2016-01-09 14:18:11

标签: c# wpf listview

An Online-Shopping sites Filter example taken from amazon.com

如果你们访问amazon.com并搜索"电影",你会看到上面的过滤器。

在我的应用中,我有一个ListView,里面有一些MovieItem个。几天之前, 我已使用搜索框成功过滤了ListView。然后昨天,我访问了amazon.com并查看了上面的过滤器面板。我想知道我是否也可以在我的应用程序中应用它。因此,为ListView的项目创建了一个简单的过滤器面板:

My Filter Panel

不幸的是,由于我是wpf和c#语言的新手,我不知道这样做:(

那么有人可以告诉我该怎么办?

仅供参考,MovieItem课程:

    public class MovieItem
    {
    public string aRomajiTitle { get; set; }
    public string bEnglishTitle { get; set; }
    public string cType { get; set; }
    public string dScore { get; set; }
    public string eEpisodes { get; set; }
    public string fJapaneseTitle { get; set; }
    public string gGenres { get; set; }
    public string hSynopsis { get; set; }
    public string iDuration { get; set; }
    public string jStatus { get; set; }
    public string kMALID { get; set; }
    public string lMyStatus { get; set; }
    public string mDownloaded { get; set; }
    public string nWatched { get; set; }
    public string oMyScore { get; set; }
    public string pKeywords { get; set; }
    public string qPicURL { get; set; }
    public string rLocalPic { get; set; }
    public string sEpsAcc { get; set; }
    public string tRewatched { get; set; }
    public string uNotes { get; set; }
    public string zImage_url_med { get; set; }
    public string zImage_url_sml { get; set; }
    public string zStart_date { get; set; }
    public string zEnd_date { get; set; }
    public string zHashtag { get; set; }
    public string zSource { get; set; }
    public string zSynonyms { get; set; }
    public string zImageBanner { get; set; }
    public string zYoutube_ID { get; set; }
    public bool zAdult { get; set; }
    public int? zPopularity { get; set; }
    public string zRelation_type { get; set; }
    public string zRole { get; set; }
    public bool favourite { get; set; }
    public int? season { get; set; }
    public List<Subclass_SmallReviewModel> reviews { get; set; }
    public List<CharacterWithActor_Model> characters { get; set; }
    public List<Staff_Model_Small> staff { get; set; }
    public List<OP_SMALL_Model> OPS { get; set; }
    public List<ED_SMALL_Model> EDS { get; set; }
    public List<Subclass_Studio_Model> studio { get; set; }
    public List<Subclass_Ext_Links> external_links { get; set; }
    public Subclass_Airing zAiring { get; set; }

}

ListView XAML:

<ListView x:Name="DM_AllMovies_List" Panel.ZIndex="0" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling" HorizontalAlignment="Left"  Height="671" VerticalAlignment="Top" Width="902" ScrollViewer.HorizontalScrollBarVisibility="Auto" Foreground="Black" ScrollViewer.CanContentScroll="True" BorderBrush="#FFC54B4B" BorderThickness="3" Background="White" MouseDown="DM_AllMovie_List_MouseDown" Margin="0,0,0,-3">
                            <ListView.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <mwc:VirtualizingWrapPanel Orientation="Horizontal"/>
                                </ItemsPanelTemplate>
                            </ListView.ItemsPanel>
                        </ListView>

ListView ItemsSourceList的{​​{1}}。

MovieItem

告诉我您是否需要查看 public void LoadMyList() { DM_AllMovies_List.ItemsSource = null; List<MovieItem> MovieDataSource_AllMovies = new List<MovieListViewItem_V2>(); string json = File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory + @"Database\DMTitles.col"); List<MovieItem> js = JsonConvert.DeserializeObject<List<MovieListViewItem_V2>>(json); DM_AllMoview_List.ItemsSource = js; } &#39; ListView

1 个答案:

答案 0 :(得分:1)

您好我理解您需要使用一些过滤谓词来过滤整个项目集合。如果是这样,我可以建议您将CollectionView用作集合的SourceItems。另外请注意,您从XAML绑定它们的所有集合必须是ObservableCollection类型,否则您的应用程序中会出现内存泄漏。在这里,我放了几篇文章来帮助您了解如何使用CollectionView:

  1. filter an observable collection
  2. How to Navigate, Group, Sort and Filter Data in WPF
  3. 此致