Converter is a Markup
If you want simplify your code it’s better to make a converter who is also a markup
Previous code for converter
public class BoolToVisivilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (bool)value ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Previous code for xaml
<Grid Margin="10,245,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<Grid.Resources>
<local:BoolToVisivilityConverter x:Key="btvc" />
</Grid.Resources>
<TextBox Width="772"
Height="52"
Text="{Binding Dossier, FallbackValue=xxxxx}"
TextWrapping="Wrap"
Visibility="{Binding IsVisible, Converter={StaticResource btvc}}" />
</Grid>
And new code for converter
public class BoolToVisivilityMarkupConverter : MarkupExtension, IValueConverter
{
public override object ProvideValue(IServiceProvider serviceProvider) => this;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (bool)value ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
and xaml
<TextBox HorizontalAlignment="Left"
Height="38"
Margin="10,320,0,0"
TextWrapping="Wrap"
Text="{Binding Dossier, FallbackValue=xxxxx}"
VerticalAlignment="Top"
Width="772"
Visibility="{Binding IsVisible, Converter={local:BoolToVisivilityMarkupConverter}}" />
see the difference
