<TextBlock Text="Текст 1" Visibility="{Binding Converter={converters:BooleanToVisibilityConverter}}"/>
<TextBlock Text="Текст 2" Visibility="{Binding Converter={converters:BooleanToVisibilityConverter Inversed=True}}"/>
public class BooleanToVisibilityConverter : MarkupExtension, IValueConverter
{
/// <summary>
/// Возвращать результат с инверсией
/// </summary>
public bool Inversed { get; set; }
/// <summary>
/// Состояние при ложном результате - Hidden или Collapsed (по умолчанию - Collapsed)
/// </summary>
public bool Hidden { get; set; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var val = (bool)value;
val = Inversed ? !val : val;
if (val)
{
return Visibility.Visible;
}
return Hidden ? Visibility.Hidden : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var val = (Visibility)value;
var res = !Inversed;
switch (val)
{
case Visibility.Visible:
return res;
default:
return !res;
}
}
#region MarkupExtension
public BooleanToVisibilityConverter()
{
}
/// <summary>
/// Отображать конвертер в списке
/// </summary>
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
#endregion
}
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} x {1} Test">
<Binding ElementName="TextBox1" Path="Text" />
<Binding ElementName="TextBox2" Path="Text" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
public static class NumericHelper
{
public static Int32 ToInt32(this Object line)
{
return Convert.ToInt32(line);
}
}
int x = NumericHelper.ToInt32(myvar);