ivalueconverter

Loading images source dynamically with IValueConverter

我们两清 提交于 2019-11-29 15:44:36
I've problems with IValueconverter and dynamically load a row grid image: public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string Type = (string)value; Uri uri; try { uri = new Uri("/XConsole;component/Images/" + Type + ".png", UriKind.Relative); return new System.Windows.Media.Imaging.BitmapImage(uri) { CacheOption = BitmapCacheOption.None }; } catch (Exception e) { //donothing } uri = new Uri("/XConsole;component/Images/Type_SYSTEM.png", UriKind.Relative); return new System.Windows.Media.Imaging.BitmapImage(uri) { CacheOption

WPF IValueConverter - converting multiple values into a single value

前提是你 提交于 2019-11-29 14:53:10
I'm trying to maintain someone else's code right now where that person is a WPF expert. I, on the other hand, am not. :) The code uses the IValueConverter to convert a state enumeration into a boolean which governs whether or not a UserControl is displayed on the screen. I've discovered a shortcoming that a single enumeration in this circumstance is not enough, there's actually another boolean that needs to be considered as well. Is there another object that could be used that would take 2 items in as arguments in order to do a conversion? (The "converter" parameter is already being used.) A

Why do I get a DependencyProperty.UnsetValue when converting a value in a MultiBinding?

♀尐吖头ヾ 提交于 2019-11-29 09:04:26
I have an extremely simple IMultiValueConverter that simply OR's two values. In the example below, I want to invert the first value using an equally simple boolean inverter. <MultiBinding Converter="{StaticResource multiBoolToVis}"> <Binding Path="ConditionA" Converter="{StaticResource boolInverter}"/> <Binding Path="ConditionB"/> </MultiBinding> and the inverter: public class BoolInverterConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value is bool) { return !(

How to handle exception in Value converter so that custom error message can be displayed

左心房为你撑大大i 提交于 2019-11-29 03:37:33
I have a textbox that is bound to a class with a property of type Timespan, and have written a value converter to convert a string into TimeSpan. If a non number is entered into the textbox, I would like a custom error message to be displayed (rather than the default 'input string is in the wrong format'). The converter code is: public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture) { try { int minutes = System.Convert.ToInt32(value); return new TimeSpan(0, minutes, 0); } catch { throw new FormatException("Please enter a number"); } } I have set

What is the use of ConvertBack method in IValueConverter interface?

自作多情 提交于 2019-11-29 00:55:29
What is the use of ConvertBack method in IValueConverter interface. When it will call? Or what is the order of invocation of Convert and ConvertBack method. I have ask question here because: I have bound one property of codebehind to TEXTBOX’s TEXT Property and using convertor for that property, then first Convert Method invoke and when I change TEXT in TEXTBOX nothing happen but as soon as I close the form ConvertBack method invoke. what is this, there is not any rules that define when to fire ConvertBack method? NOTE: you may be find that this is possible duplicate of other question on this

Improved IValueConverter — MarkupExtension or DependencyObject?

非 Y 不嫁゛ 提交于 2019-11-28 19:41:32
I saw online 2 different approaches to enhancing an IValueConverter. One of them extended a ValueConverter from MarkupExtension, the other from DependencyObject. I can't extend from both, so I'm wondering if any one is better than the other? Deriving from each gives you different kind of power and flexibility: Deriving from MarkupExtension enables you to use the value converter without making it a static resource, as described below: public class DoubleMe : MarkupExtension, IValueConverter { public override object ProvideValue(IServiceProvider serviceProvider) { return this; } public object

Should I declare converters in App.xaml or as a per-file resource?

允我心安 提交于 2019-11-28 19:36:16
When declaring converters in a WPF application, should I: Declare all my converters in the App.xaml (i.e. in <Application.Resources/> ) so it's available to the entire application Declare only needed converters for each Page / Window / ResourceDictionary / UserControl etc. in their Resources section Something else entirely Regarding readability, method 1 seems the best to me, but my question is about performance. Which method is the most resource efficient in terms of performance, memory, etc.? Yogesh Well, I just don't declare them in xaml at all. Instead, I additionally derive a converter of

ImageSourceConverter error for Source=null

孤街醉人 提交于 2019-11-28 18:33:24
I'm binding the Source property of an Image to a string. This string may be null in which case I just don't want to display an Image. However, I'm getting the following in my Debug output: System.Windows.Data Error: 23 : Cannot convert '<null>' from type '<null>' to type 'System.Windows.Media.ImageSource' for 'en-AU' culture with default conversions; consider using Converter property of Binding. NotSupportedException:'System.NotSupportedException: ImageSourceConverter cannot convert from (null). at System.ComponentModel.TypeConverter.GetConvertFromException(Object value) at System.Windows

Converter With Multiple Parameters

China☆狼群 提交于 2019-11-28 18:17:31
Does anyone know how to use converter with Multiple parameter in a Windows Phone 7 Application? Thanks in Advance. Converters always implement IValueConverter . That means a call to Convert or ConvertBack passes a single additional parameter. That parameter is extracted from the XAML. As Hitesh Patel suggests there is nothing to stop you putting more than one value into the parameter, so long as you have a delimiter to separate them out later, but you cannot use a comma as that delimits the XAML! e.g. XAML <TextBlock Text="{Binding Path=ReleaseDate, Mode=OneWay, Converter={StaticResource

WPF BooleanToVisibilityConverter that converts to Hidden instead of Collapsed when false?

情到浓时终转凉″ 提交于 2019-11-28 16:49:23
Is there a way to use the existing WPF BooleanToVisibilityConverter converter but have False values convert to Hidden instead of the default Collapsed, or should I just write my own? I'm on a project where it's tremendous overhead to do something simple like this (shared stuff goes into a separate solution, and the rebuild/checkin/merge process is an overgrown mutated behemoth of a process), so I'd prefer if I could just pass a parameter to the existing one than to jump through the hoops just mentioned. Quartermeister Unfortunately, it only converts to Visible or Collapsed, so you'll have to