ivalueconverter

Loading images source dynamically with IValueConverter

本小妞迷上赌 提交于 2019-11-28 09:22:12
问题 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

WPF IValueConverter - converting multiple values into a single value

余生长醉 提交于 2019-11-28 08:30:41
问题 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

WPF MVVM Radio buttons on ItemsControl

给你一囗甜甜゛ 提交于 2019-11-28 06:23:48
I've bound enums to radio buttons before, and I generally understand how it works. I used the alternate implementation from this question: How to bind RadioButtons to an enum? Instead of enumerations, I'd like to generate a runtime-enumerated set of a custom type and present those as a set of radio buttons. I have gotten a view working against a runtime-enumerated set with a ListView , binding to the ItemsSource and SelectedItem properties, so my ViewModel is hooked up correctly. Now I am trying to switch from a ListView to a ItemsControl with radio buttons. Here's as far as I've gotten:

Use IValueConverter with DynamicResource?

我怕爱的太早我们不能终老 提交于 2019-11-27 20:12:53
Is there a way to define a converter when using the DynamicResource extension? Something in the lines of <RowDefinition Height="{Binding Source={DynamicResource someHeight}, Converter={StaticResource gridLengthConverter}}" /> which unfortunately gives me the following excpetion: A 'DynamicResourceExtension' cannot be set on the 'Source' property of type 'Binding'. A 'DynamicResourceExtension' can only be set on a DependencyProperty of a DependencyObject. I know i am really late to this but what definitely works is using a BindingProxy for the DynamicResource like this <my:BindingProxy x:Key=

Format part of the text of TextBlock using iValueConverter

江枫思渺然 提交于 2019-11-27 19:25:09
问题 I want to make part of the text of a textblock bold. This is what i tried in the IValueConverter but it does not seem to work. public class Highlighter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return null; } return "Question1:<Bold>Answer1</Bold>, Question2:<Bold>Answer2</Bold>, Question3:<Bold>Answer3</Bold>"; } public object ConvertBack(object value, Type targetType, object parameter, System

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

廉价感情. 提交于 2019-11-27 17:31:38
问题 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

Is there a way to chain multiple value converters in XAML?

非 Y 不嫁゛ 提交于 2019-11-27 17:11:28
I've got a situation in which I need to show an integer value, bound to a property on my data context, after putting it through two separate conversions: Reverse the value within a range (e.g. range is 1 to 100; value in datacontext is 90; user sees value of 10) convert the number to a string I realise I could do both steps by creating my own converter (that implements IValueConverter). However, I've already got a separate value converter that does just the first step, and the second step is covered by Int32Converter. Is there a way I can chain these two existing classes in XAML without having

What are the special values of WPF's Binding engine when converting values?

只谈情不闲聊 提交于 2019-11-27 16:51:31
问题 I already know about the Binding.DoNothing that one can return from an IValueConverter implementation to signify that no other operation should take place. However, I cannot find a reference, or documentation nicely summing out, what the other special values are - such as returning the fallback value. What are they? 回答1: Binding.DoNothing is an object instance that you actively return from a value converter ; it instructs the binding engine to not update the value of the target property at

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

六眼飞鱼酱① 提交于 2019-11-27 12:26:13
问题 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

ImageSourceConverter error for Source=null

穿精又带淫゛_ 提交于 2019-11-27 11:27:00
问题 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