我想基於輸入文本篩選ListView項目,並且因爲選擇被刪除,我試圖將可見性設置爲基於布爾值的不可見(我希望這將不會刪除項目的選擇)基於布爾值的ListView項目可見性
我使用了一些舊帖子創建此代碼,但我想不通爲什麼它不工作:
<ListView x:Name="osebe_listView" Margin="0,0,40,0" SelectionMode="Multiple" SelectionChanged="osebe_listView_SelectionChanged" BorderThickness="0" ScrollViewer.HorizontalScrollBarVisibility="Hidden">
<ListView.Resources>
<Style TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<DataTrigger Binding="{Binding visible}" Value="False">
<Setter Property="Visibility" Value="Hidden"/>
</DataTrigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Background" Value="#1AFFFFFF" />
<Setter Property="BorderThickness" Value="0"/>
</Style>
<Style TargetType="{x:Type ColumnDefinition}">
<Setter Property="Width" Value="10"/>
</Style>
</ListView.Resources>
<ListView.View>
<GridView>
<GridViewColumn Header="Naziv podjetja" DisplayMemberBinding="{Binding nazivPodjetja}"/>
<GridViewColumn Header="Ime" DisplayMemberBinding="{Binding ime}" Width="25"/>
<GridViewColumn Header="Priimek" DisplayMemberBinding="{Binding priimek}" Width="{Binding ActualWidth, ElementName=helperField}"/>
<GridViewColumn Header="Naslov" DisplayMemberBinding="{Binding naslov}" Width="{Binding ActualWidth, ElementName=helperField}"/>
<GridViewColumn Header="Pošta" DisplayMemberBinding="{Binding posta}" Width="{Binding ActualWidth, ElementName=helperField}"/>
<GridViewColumn Header="Mobilna številka" DisplayMemberBinding="{Binding mobilnaSt}" Width="{Binding ActualWidth, ElementName=helperField}"/>
<GridViewColumn Header="Stacionarna številka" DisplayMemberBinding="{Binding stacionarnaSt}" Width="{Binding ActualWidth, ElementName=helperField}"/>
<GridViewColumn Header="E-naslov" DisplayMemberBinding="{Binding eMail}" Width="{Binding ActualWidth, ElementName=helperField}"/>
<GridViewColumn Header="Skupina" DisplayMemberBinding="{Binding skupina}" Width="{Binding ActualWidth, ElementName=helperField}"/>
</GridView>
</ListView.View>
</ListView>
文字過濾方法(這是工作的罰款):
private void isci_tb_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
if (isci_tb.Text == "search") return;
string s = isci_tb.Text;
if (isci_tb.Text == "")
{
foreach (Oseba o in seznamOseb)
{
//osebe_listView.Items.Add(o);
o.visible = true;
}
}
//else
//{
// osebe_listView.Items.Clear();
foreach (Oseba o in seznamOseb)
{
if(! (contejns(o.ime, s) || contejns(o.priimek, s) || contejns(o.mobilnaSt.ToString(), s) || contejns(o.posta, s) || contejns(o.nazivPodjetja, s) || contejns(o.stacionarnaSt.ToString(), s) || contejns(o.naslov, s) || contejns(o.eMail, s)))
{
o.visible = false;
}
}
//}
}
catch { }
}
我發現了code here
請注意,我沒有使用任何數據綁定。我錯過了什麼?
是否Oseba類實現INotifyPropertyChanged接口? – mm8
在他正在使用' '的鏈接中,無法在代碼中找到它。 'o.visible'沒有做任何事情,我猜... –
它沒有。我怎樣才能實現它?我認爲設置這樣的屬性就足夠了,因爲我沒有在那篇文章中找到任何額外的代碼 – someone1