One of the best uses for markup extensions is for easier usage of IValueConverter. In the sample below BoolToVisibilityConverter is a value converter but since it's instance independent it can be used without the normal hasles of a value converter with the help of markup extension. In XAML just use
Visibility="{Binding [BoolProperty], Converter={[xmlns]:BoolToVisibilityConverter}}"
and you can set item visibility to bool value.
public class BoolToVisibilityConverter : MarkupExtension, IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool)
return (bool)value ? Visibility.Visible : Visibility.Collapsed;
else
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Visibility)
{
if ((Visibility)value == Visibility.Visible)
return true;
else
return false;
}
else
return false;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
}