[英]ListView SelectedItem not firing in MVVM app using Template 10 UWP
[英]Filter Listview Using MVVM in Uwp
視圖
<StackPanel>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Row="2">
<RadioButton Content="Verified" IsChecked="{Binding Path=RadioAChecked,Mode=TwoWay}" Foreground="{StaticResource foretwo}"/>
<RadioButton Content="Not Verified" IsChecked="{Binding Path=RadioBChecked,Mode=TwoWay}" Foreground="{StaticResource foretwo}"/>
</StackPanel>
<ListView ItemsSource="{Binding BillList}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Bill_Type}" Style="{StaticResource textblock}"/>
<TextBlock Text="{Binding Bill_Status}" Style="{StaticResource textblock}"/>
<TextBlock Text="{Binding Bill_Date}" Style="{StaticResource textblock}"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
視圖模型
public class BillViewModel : BindableBase
{
IBillDataServices _service;
public BillViewModel(IBillDataServices service)
{
_service = service;
_billList = _service.GetAllBill();
}
private ObservableCollection<BillModel> _billList;
public ObservableCollection<BillModel> BillList
{
get
{
return _billList;
}
set
{
_billList = value;
RaisePropertyChanged("BillList");
}
}
private bool _radioAChecked;
public bool RadioAChecked
{
get { return _radioAChecked; }
set
{
if (_radioAChecked == true)
{
}
}
}
private bool _radioBChecked;
public bool RadioBChecked
{
get { return _radioBChecked; }
set
{
_radioBChecked = true;
if (_radioBChecked == true)
{
}
}
}
我的viewmodel(ViewModel)中有一個名為_billList的集合。該集合包含Bill_Type,Bill_Status和Bill_Date。 在這里,我需要在列表視圖中進行過濾。 我在集合中具有Bill_Status的值,例如(“是”和“否”)。 如果我檢查了第一個單選按鈕,則Bill_Status =“ Yes”的行應綁定到listview。 如果選中第二個單選按鈕,則Bill_Status =“ No”行應綁定到列表視圖。 如何在uwp中這樣做? 請幫助我。
完成此任務的最快方法是使用Linq過濾集合並將結果傳遞給可觀察的集合。
為此,您需要保留所有值的原始集合,您可以使用它們進行Linq過濾。
過濾后,將結果設置為可觀察的集合。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.