Answer the question
In order to leave comments, you need to log in
How to make multiple converters in xaml?
In Angular, you can make several filters over text, for example
<div ng-bind="vm.value | filter1| filter2| filter3"
<Label Font="20" Text="{Binding MovingState.HashRate,Converter={StaticResource FloatConverter...
Answer the question
In order to leave comments, you need to log in
In your case, the creation of a special custom converter is suitable, which will make it from a number to a string, and then process the string.
Another option is MultiBinding. A special multi-converter is created, in which several ordinary bindings are indicated. But they are processed in parallel, so if you first need to make the first converter, and then use its result in another converter, then this will not work, all data is processed in a multiconverter.
But multibinding works in WPF, but not in Silverlight. But there is a workaround for Silverlight: www.codeproject.com/Articles/286171/MultiBinding-i...
Here is an example of a multi-converter that takes multiple bools and checks if they are all true (or false - you can choose).
Converter usage:
xmlns:converters="clr-namespace:MyProject.Converters"
<CheckBox x:Name="Checkbox1" Content="Чекбокс 1"/>
<CheckBox x:Name="Checkbox2" Content="Чекбокс 2"/>
<ToggleButton Content="Кнопка">
<ToggleButton.IsEnabled>
<MultiBinding Converter="{converters:BooleanMultiConverter Type=AllTrue}">
<Binding Path="IsChecked" ElementName="Checkbox1"/>
<Binding Path="IsChecked" ElementName="Checkbox2"/>
</MultiBinding>
</ToggleButton.IsEnabled>
</ToggleButton>
using System;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;
namespace MyProject.Converters
{
public class BooleanMultiConverter : MarkupExtension, IMultiValueConverter
{
/// <summary>
/// Перечисление типа конвертера
/// </summary>
public enum Types
{
AllTrue,
AllFalse,
AnyTrue,
AnyFalse,
}
/// <summary>
/// Тип конвертера, по умолчанию - AllTrue
/// </summary>
public Types Type { get; set; }
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
switch (Type)
{
case Types.AllTrue:
return values.All(v => (bool)v);
case Types.AllFalse:
return values.All(v => !(bool)v);
case Types.AnyTrue:
return values.Any(v => (bool)v);
case Types.AnyFalse:
return values.Any(v => !(bool)v);
default:
throw new InvalidOperationException();
}
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
return new[] { DependencyProperty.UnsetValue };
}
#region MarkupExtension
public BooleanMultiConverter()
{
}
/// <summary>
/// Отображать конвертер в списке
/// </summary>
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
#endregion
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question