I have a pretty straightforward IValueConverter that converts a IList<string>
into a comma separated string of strings. Trouble is the collection (which is a ObservableCollection) is not attempting to update the text, I can tell because a debug point in the IValueConverter shows that is is not being called after the initial binding on load.
The converter (This part seems to work fine when actually called)
public class CollectionToCommaSeperatedString : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null)
return parameter.ToString();
if (((IList<string>)value).Count > 0)
return String.Join(", ", ((IList<string>)value).ToArray()) ?? parameter.ToString();
else
return parameter.ToString();
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
The bound element:
<TextBlock Text="{Binding SelectedChannels, ConverterParameter='(Click to select channels)', Converter={StaticResource CollectionToCommaSeperatedString}, ElementName=userControl, Mode=OneWay}" HorizontalAlignment="Left" VerticalAlignment="Top"/>
The CB for the property:
public ObservableCollection<string> SelectedChannels
{
get { return (ObservableCollection<string>)GetValue(SelectedChannelsProperty); }
set { SetValue(SelectedChannelsProperty, value); }
}
public static readonly DependencyProperty SelectedChannelsProperty =
DependencyProperty.Register("SelectedChannels", typeof(ObservableCollection<string>), typeof(ChannelSelector), new PropertyMetadata(new ObservableCollection<string>()));
SelectedChannels
? – SinatrText
the binding is ignoring theINotifyCollectionChanged
. You would have to go with standard procedure (subscribing to event). – Sinatr