本文整理汇总了C#中IValueConverter类的典型用法代码示例。如果您正苦于以下问题:C# IValueConverter类的具体用法?C# IValueConverter怎么用?C# IValueConverter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IValueConverter类属于命名空间,在下文中一共展示了IValueConverter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetView
public override View GetView(PropertyInfo property, object o, out BindableProperty targetProperty, out IValueConverter converter)
{
targetProperty = Label.TextProperty;
converter = new ValueConverter();
return new Label();
}
示例2: ChangeObjectValueAction
public ChangeObjectValueAction(BoundPropertyDescriptor boundPropertyDescriptor, object originalValue, object newValue, IValueConverter stringConverter)
{
_boundPropertyDescriptor = boundPropertyDescriptor;
_originalValue = originalValue;
_newValue = newValue;
_stringConverter = stringConverter;
}
示例3: EncryptingValueConverter
public EncryptingValueConverter(
IValueConverter decoratedValueConverter,
IEncryptionAlgorithmFactory encryptionAlgorithmFactory)
{
_decoratedValueConverter = decoratedValueConverter;
_encryptionAlgorithm = encryptionAlgorithmFactory.GetAlgorithm(decoratedValueConverter.Type);
}
示例4: GetEnumSource
public static IEnumerable<EnumMemberInfo> GetEnumSource(Type enumType, bool useUnderlyingEnumValue = true, IValueConverter nameConverter = null, bool splitNames = false, EnumMembersSortMode sortMode = EnumMembersSortMode.Default, Func<string, bool, string> getKnownImageUriCallback = null, bool showImage = true, bool showName = true) {
var result = enumType.GetFields(BindingFlags.Static | BindingFlags.Public)
.Where(field => DataAnnotationsAttributeHelper.GetAutoGenerateField(field))
.Select(field => {
Enum value = (Enum)field.GetValue(null);
string name = GetEnumName(field, value, nameConverter, splitNames);
var imageInfo = GetImageInfo(MetadataHelper.GetAttribute<ImageAttribute>(field), MetadataHelper.GetAttribute<DXImageAttribute>(field), null, getKnownImageUriCallback);
ImageSource image = ViewModelBase.IsInDesignMode ? null : (imageInfo.Item1 ?? imageInfo.Item2).With(x => (ImageSource)new ImageSourceConverter().ConvertFrom(x));
return new EnumMemberInfo(name, DataAnnotationsAttributeHelper.GetFieldDescription(field), useUnderlyingEnumValue ? GetUnderlyingEnumValue(value) : value, image, showImage, showName,
DataAnnotationsAttributeHelper.GetFieldOrder(field));
});
switch(sortMode) {
case EnumMembersSortMode.DisplayName:
result = result.OrderBy(x => x.Name);
break;
case EnumMembersSortMode.DisplayNameDescending:
result = result.OrderByDescending(x => x.Name);
break;
case EnumMembersSortMode.DisplayNameLength:
result = result.OrderBy(x => x.Name.Length);
break;
case EnumMembersSortMode.DisplayNameLengthDescending:
result = result.OrderByDescending(x => x.Name.Length);
break;
}
return result.OrderBy(x => (x.Order != null) ? x.Order : DefaultDisplayOrder).ToArray();
}
示例5: ValueConversionStep
public ValueConversionStep( Type targetType, IValueConverter valueConverter )
{
Arg.NotNull( targetType, nameof( targetType ) );
Arg.NotNull( valueConverter, nameof( valueConverter ) );
this.targetType = targetType;
converter = valueConverter;
}
示例6: CollectionSynchronizer
public CollectionSynchronizer(INotifyCollectionChanged source, ObservableCollection<object> target, IValueConverter valueConverter)
{
_source = source;
_target = target;
_valueConverter = valueConverter;
_source.CollectionChanged += OnSourceCollectionChanged;
}
示例7: ValueConverterConvention
/// <summary>
/// Constructor
/// </summary>
/// <param name="converter"></param>
/// <param name="filter"></param>
public ValueConverterConvention(IValueConverter converter, Func<DependencyProperty, PropertyInfo, bool> filter)
{
if (null == converter) throw new ArgumentNullException("converter");
if (null == filter) throw new ArgumentNullException("filter");
Converter = converter;
Filter = filter;
}
示例8: Prompt
public string Prompt(string message, FlowDocument comment, IValueConverter converter, int length)
{
PromptDialog pd = new PromptDialog(App.Current.MainWindow, message, comment, converter, length);
string r = (bool) ShowDialog(pd) ? pd.Keypad.Text : null;
pd.Close();
return r;
}
示例9: SetBinding
public static BindingExpressionBase SetBinding(this FrameworkElement target, DependencyProperty dp, object source, string path, IValueConverter converter)
{
Binding b = new Binding(path);
b.Source = source;
b.Converter = converter;
return BindingOperations.SetBinding(target, dp, b);
}
示例10: SetBinding
/// <summary>
/// Sets a binding from code
/// </summary>
/// <param name="element"></param>
/// <param name="property"></param>
/// <param name="source"></param>
/// <param name="path"></param>
/// <param name="converter"></param>
public static void SetBinding(FrameworkElement element, DependencyProperty property, object source, string path, IValueConverter converter = null)
{
Binding binding = new Binding();
binding.Source = source;
binding.Path = new PropertyPath(path);
binding.Converter = converter;
element.SetBinding(property, binding);
}
示例11: GetRedactFunc
private static Func<bool, object, string> GetRedactFunc(IValueConverter valueConverter)
{
return
(redactEnabled, value) =>
redactEnabled
? "XXXXXXXXXX"
: valueConverter.GetString(value, null);
}
示例12: CommandForMethod
/// <summary>
/// Initializes a new instance of <see cref="CommandForMethod"/>
/// </summary>
/// <param name="target">Target to bind to for the method, typically a ViewModel</param>
/// <param name="methodName">Name of the method to bind to</param>
/// <param name="canExecuteWhen">Optionally a reference to either a property or method that gets called to check if the command can execute</param>
/// <param name="parameterConverter">Optionally a <see cref="IValueConverter"/> that will be used for converting value to the method</param>
/// <remarks>
/// The canExecuteWhen parameter can take the name of a property or a method. If it is
/// a property and the declaring type implements <see cref="INotifyPropertyChanged"/>,
/// it will honor that and actually fire off the CanExecuteChanged if the property changes
/// state. The property needs to be of type boolean, and a method can take one parameter,
/// and the CommandParameter property from the view will be the content if so. The method
/// needs to return a boolean.
/// </remarks>
public CommandForMethod(object target, string methodName, string canExecuteWhen = null, IValueConverter parameterConverter = null)
{
_target = target;
_canExecuteWhen = canExecuteWhen;
_parameterConverter = parameterConverter;
GetMethod(target, methodName);
if (!string.IsNullOrEmpty(canExecuteWhen)) SetupCanExecuteWhen(target, canExecuteWhen);
}
示例13: SimpleValueType
public SimpleValueType(Type type, IValueConverter valueConverter)
: base(type)
{
if (valueConverter == null)
throw new ArgumentNullException("valueConverter");
this.ValueConverter = valueConverter;
}
示例14: DefaultRunnableFactory
/// <summary>
/// Initializes a new instance of the <see cref="DefaultRunnableFactory"/> class.
/// </summary>
public DefaultRunnableFactory(IEnumerable<Type> availableRunnables, IValueConverter valueConverter = null, INameMatcher runnableNameMatcher = null, INameMatcher parameterNameMatcher = null,
IServiceFactory serviceFactory = null)
{
AvailableRunnables = availableRunnables ?? Enumerable.Empty<Type>();
RunnableNameMatcher = runnableNameMatcher ?? new EqualityNameMatcher();
ParameterNameMatcher = parameterNameMatcher ?? new EqualityNameMatcher();
ValueConverter = valueConverter ?? new EmptyValueConverter();
ServiceFactory = serviceFactory;
}
示例15: CustomBinding
public CustomBinding(string propertyName, object dataSource, string dataMember, IValueConverter valueConverter, object converterParameter = null)
: base(propertyName, dataSource, dataMember)
{
if (valueConverter != null)
this._converter = valueConverter;
this._converterCulture = Thread.CurrentThread.CurrentUICulture;
this._converterParameter = converterParameter;
}