I have an ICollectionView
, called RepozitorijumWrapper
which should display my entities based on six fields. The fields are two TextBox
and four DateTimePicker
elements. Basically, every time any of those elements change (even by a number/letter) I want the list to update.
My DateTimePicker
and TextBox
elements are bound to DateTime and string properties, that have the RepozitorijumWrapper.Refresh()
code in their setter. When I tested my application, the filter did work, but only once you left the field. After that I tried calling the Refresh()
method from the controller, or rather using the TextChanged
event for the TextBox
elements, and the ValueChanged
for the DateTimePicker
s. This changed nothing. The filter does work, but it isn't refreshed the way I'd like it to refresh.
Since my code is pretty much six copies of the same thing, with changed names and types, I'll only paste one instance of each relevant part of code.
Here's the property:
public string SifraTima
{
get {return sifraTima;}
set
{
if(!sifraTima.Equals(value))
{
sifraTima = value;
RepozitorijumWrapper.Refresh();
}
}
}
Here's the XAML for that property:
<TextBox x:Name="txtSifraTima" Grid.Column="1" Grid.Row="2" Margin="3,3,30,3" Text="{Binding Path=SifraTima}" TextChanged="txtSifraTima_TextChanged" />
Here's the event handler:
private void txtSifraTima_TextChanged(object sender, TextChangedEventArgs e)
{
presenter.RepozitorijumWrapper.Refresh();
}
Here's my ICollectionView, created in the constructor of my presenter class:
RepozitorijumWrapper = CollectionViewSource.GetDefaultView(rezervacije.Kolekcija);
RepozitorijumWrapper.Filter = itm =>
((Rezervacija)itm).SifraTerena.Contains(SifraTerena) &&
((Rezervacija)itm).SifraTima.Contains(SifraTima) &&
((Rezervacija)itm).VremeZauzimanja <= VremeZauzimanjaDo &&
((Rezervacija)itm).VremeZauzimanja >= VremeZauzimanjaOd &&
((Rezervacija)itm).VremeOslobadjanja <= VremeOslobadjanjaDo &&
((Rezervacija)itm).VremeOslobadjanja >= VremeOslobadjanjaOd;
Your binding on the Text
property of the TextBox
is set to only update the property after the focus is lost by default. To change that behavior, you can specify a value for UpdateSourceTrigger
like so:
Text="{Binding Path=SifraTima, UpdateSourceTrigger=PropertyChanged}"
MSDN has more information on UpdateSourceTrigger