For example i have a viewmodel with something like this:
public class MyViewModel
{
public ObservableCollection { get; set; }
}
public abstract class Person { }
public class Employee : Person { }
public class Boss : Person { }
Depending on the type of the person I wan’t some changes to my ListItemTemplate. I have a value converter like this:
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value == null) return Visibility.Collapsed;
return value is Boss ? Visibility.Visible : Visibility.Collapsed;
}
How do I bind the Visibilty property to the converter?
Things i’ve done:
<Border Visibility="{Binding Path=self, Converter={StaticResource BossVisibilityConverter}}">
<Border Visibility="{Binding Path=this, Converter={StaticResource BossVisibilityConverter}}">
if the DataContext is set to your ViewModel instance, then just try the following:
Also, you might want to look into a DataTemplateSelector
in xaml:
Then you can use the personDataTemplateSelector as the value of an ItemTemplateSelector in a ListView, or some other ItemsControl.