I have a property composed of email addresses of operators currently editing a record:
public ReactiveList<string> Operators { get; set; }
On the view side, I have a ListView of records, and for each of them an icon shows if the current user is an editing operator.
<FontIcon Glyph="" Visibility="{Binding Operators,
Converter={StaticResource IsUserEditingToVisibilityConverter} }" />
My problem is that the Convert() method of IsUserEditingToVisibilityConverter is not triggered when an update occurs in Operators. A TextBlock I set for debugging purpose does update though:
<TextBlock Text="{Binding Operators[0]}" />
Here's the code of IsUserEditingToVisibilityConverter:
// Taken from https://blogs.msdn.microsoft.com/mim/2013/03/11/tips-winrt-converter-parameter-binding/
public class IsUserEditingToVisibilityConverter : DependencyObject, IValueConverter
{
public UserVm CurrentUser
{
get { return (UserVm)GetValue(CurrentUserProperty); }
set { SetValue(CurrentUserProperty, value); }
}
public static readonly DependencyProperty CurrentUserProperty =
DependencyProperty.Register("CurrentUser",
typeof(UserVm),
typeof(IsUserEditingToVisibilityConverter),
new PropertyMetadata(null));
public object Convert(object value, Type targetType, object parameter, string language)
{
if (this.CurrentUser == null) return Visibility.Collapsed;
if (this.CurrentUser.EmailAddress == null) return Visibility.Collapsed;
var operators = value as IList<string>;
if (operators != null && operators.Contains(this.CurrentUser.EmailAddress))
{
return Visibility.Visible;
}
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}