![](/img/trans.png)
[英]How to move List View Item between List Views with drag and drop when the List Views are created with a click of a button? UWP C#
[英]Filter List view on item click - uwp
我有一個列表視圖,其中顯示了所選學生的主要主題和可選主題。 現在,我想在單擊列表視圖的每一行時對其進行過濾。 篩選應基於主要主題和可選主題。 表示已過濾的listview行包含任何主要主題或可選主題。
<ListView x:Name="ItemListView" Width="Auto" Height="Auto" HorizontalAlignment="Stretch">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding StudentName}" TextAlignment="Left" FontSize="20" Width="50"/>
</StackPanel>
<StackPanel>
<TextBlock Text="{Binding MainSub}" FontSize="20" TextAlignment="Center" />
</StackPanel>
<StackPanel>
<TextBlock Text="{Binding OptionalSub}" FontSize="20" TextAlignment="Center" />
</StackPanel>
<StackPanel >
<TextBlock Text="{Binding RollNo}" FontSize="20" TextAlignment="Center" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
ItemDetails messageData = new ItemDetails();
ItemListView.ItemsSource = messageData.Collection;
ItemListView.SelectedIndex = 0;
}
public class ItemDetails
{
public ItemDetails()
{
MatchList item;
item = new MatchList();
item.StudentName = "FF";
item.MainSub= selectedSub[0].ToString();//English
item.OptionalSub =selectedSub[1].ToString();//Sanskrit
item.RollNo = 922;
Collection.Add(item);
item = new MatchList();
item.StudentName = "DD";
item.MainSub= selectedSub[0].ToString();//English
item.OptionalSub =selectedSub[2].ToString();//Arabic
item.RollNo = 82;
Collection.Add(item);
item = new MatchList();
item.StudentName = "CC";
item.MainSub= selectedSub[3].ToString();//Science
item.OptionalSub =selectedSub[2].ToString();//Arabic
item.RollNo = 12;
Collection.Add(item);
item = new MatchList();
item.StudentName = "BB";
item.MainSub= selectedSub[3].ToString();//Science
item.OptionalSub =selectedSub[4].ToString();//Moral Science
item.RollNo = 22;
Collection.Add(item);
item = new MatchList();
item.StudentName = "AA";
item.MainSub= selectedSub[0].ToString();//English
item.OptionalSub =selectedSub[1].ToString();//Sanskrit
item.RollNo = 322;
Collection.Add(item);
}
List<MatchList> collection = new List<MatchList>();
public List<MatchList> Collection
{
get
{
return this.collection;
}
}
}
好吧,這個示例代碼似乎還沒有完成幾件事。
首先,我建議您將ObservableCollection
用作實際的Collection
屬性-這是必需的,以便在添加或刪除集合中的元素時通知您的View
。
其次,您需要將CollectionViewSource
到ListView ItemsSource
,並將其Source
設置為ObservableCollection
Collection屬性。
然后,最后要做的就是對ListView
的ItemSelected
做出反應,以從ObservableCollection
篩選出元素。 由於數據綁定,它應該反映回ListView。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.