2016-01-09 81 views
-1

An Online-Shopping sites Filter example taken from amazon.comWPF C#過濾ListView的項目有許多標準

如果你們參觀amazon.com並搜索「電影」,你會看到上面的過濾器。

在我的應用程序中,我有一個ListView,其中有一些MovieItem s。前幾天, 我已經用搜索框成功過濾了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> 

ListViewItemsSourceMovieItem小號List

 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; 
    } 

告訴我,如果你需要看到的ListViewItemTemplate

+0

是的,你可以做到這一點,發佈您的代碼和@Sajeetharan我添加的代碼所綁定 – Sajeetharan

+0

列表。 Thx的快速回復:) – Wahyu

+0

你可以使用linq查詢和適用於他們,只要他們選擇複選框 – Sajeetharan

回答

1

嗨,我可以理解你需要使用一些過濾器謂詞過濾整個項目集合。如果是這樣,我建議你使用CollectionView作爲你的集合的SourceItems。另外請注意,你從XAML綁定它們的所有集合都必須是ObservableCollection類型,否則你的應用程序會得到內存泄漏。在這裏,我列出了幾篇文章,以幫助您瞭解如何使用CollectionView:

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

問候,

+0

首先,thx答案:D你是對的!我需要用一些謂詞過濾列表視圖中的MovieItems。我會嘗試你的建議 – Wahyu

+0

我解決了我的問題thx給你:D – Wahyu

+0

@Wahyu不客氣! – Ilan