I have an ObservableCollection of strings and I'm tring to bind it with converter to ListBox and show only the strings that start with some prefix.
I wrote:
public ObservableCollection<string> Names { get; set; }
public MainWindow()
{
InitializeComponent();
Names= new ObservableCollection<Names>();
DataContext = this;
}
and the converter:
class NamesListConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null)
return null;
return (value as ICollection<string>).Where((x) => x.StartsWith("A"));
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
and the XAML:
<ListBox x:Name="filesList" ItemsSource="{Binding Path=Names, Converter={StaticResource NamesListConverter}}" />
but the listbox do not update after its beed update (add or remove).
I have notice that if I removes the converter from the binding its works perfectly.
What is wrong with my code?