ivalueconverter

WPF RadioButton InverseBooleanConverter not working

血红的双手。 提交于 2019-12-23 19:58:25
问题 I have two RadioButtons which I am binding to a boolean property in the ViewModel. Unfortunately I am getting an error in the converter because the 'targetType' parameter is null. Now I wasn't expecting the targetType parameter coming through to be null (I was expecting True or False). However I noticed that the IsChecked property of the RadioButton is a nullable bool so this kind of explains it. Can I correct something in the XAML or should I be changing the solution's existing converter?

ConverterParameter — Any way to pass in some delimited list?

眉间皱痕 提交于 2019-12-23 18:50:40
问题 Basically, if I have: <TextBlock Text="{Binding MyValue, Converter={StaticResource TransformedTextConverter}, ConverterParameter=?}" /> How would you go about passing in some type of array of items as the ConverterParameter. I figured I could pass in some type of delimited list, but I'm not sure what type of delimiter to use, or if there is a built-in way to pass in an array of parameters? 回答1: The ConverterParameter is of type object that means when the XAML is parsed there will not be any

Defining a Property in a IValueConverter class

别来无恙 提交于 2019-12-22 06:31:52
问题 I need to define a DependencyProperty in a converter class because I need this data to make the conversion and this data is in another object, not the one I'm binding to. My converter class is the following: public class LEGOMaterialConverter : DependencyObject, IValueConverter { public DependencyProperty MaterialsListProperty = DependencyProperty.Register("MaterialsList", typeof(Dictionary<int, LEGOMaterial>), typeof(LEGOMaterialConverter)); public Dictionary<int, LEGOMaterial> MaterialsList

Static Instance Base/Derived class

五迷三道 提交于 2019-12-22 05:49:18
问题 I would like to write a static instance property in a base class and derive this, but I am facing some problems. Here is the code for the base class - I currently have: public abstract class ResourceInstance<T> { private static T _instance; public static T Instance { get { if (_instance != null) return _instance; var method = MethodBase.GetCurrentMethod(); var declaringType = method.DeclaringType; if (declaringType != null) { var name = declaringType.Name; _instance = (T)Application.Current

WPF: How do I register additional implicit value converters?

泪湿孤枕 提交于 2019-12-21 12:40:01
问题 I found a question asking about ways to avoid adding custom value converters to one's application resources: Using Value Converters in WPF without having to define them as resources first However I'd like to go one step beyond that and register converters that are then implicit, as in this example: <SolidColorBrush Color="Blue" /> Here, I am assuming that some implicit "StringToSolidColorBrushConverter" is kicking-in that makes the example work. This example does not work: <Window.Resources>

Creating a Converter to take an ID and create an Image in Silverlight

蓝咒 提交于 2019-12-20 06:48:28
问题 I am using a WCF weather service and receiving weather information like ID, Description, and Images. It returns like this: <WeatherDescription> <WeatherID>1</WeatherID> <Description>Thunder Storms</Description> <PictureURL> http://ws.cdyne.com/WeatherWS/Images/thunderstorms.gif </PictureURL> </WeatherDescription> Now in the XAML I am showing my data in a dataGrid as so: <sdk:DataGridTextColumn Header="ID" Binding="{Binding WeatherID}" /> The above binding is to another function of the service

Using Unity to inject objects into IValueConverter instance

删除回忆录丶 提交于 2019-12-19 07:11:23
问题 I have an instance of IValueConverter in a Silverlight 5 project, which converts custom data into different colors. I need to read the actual color values from a database (as these can be edited by the user). Since Silverlight uses asynchronous calls to load the data through Entity Framework from the database, I created a simple repository, which holds the values from the db. The interface: public interface IConfigurationsRepository { string this[string key] { get; } } The implementation:

how to pass an integer as ConverterParameter?

对着背影说爱祢 提交于 2019-12-18 10:14:40
问题 I am trying to bind to an integer property: <RadioButton Content="None" IsChecked="{Binding MyProperty, Converter={StaticResource IntToBoolConverter}, ConverterParameter=0}" /> and my converter is: [ValueConversion(typeof(int), typeof(bool))] public class IntToBoolConverter : IValueConverter { public object Convert(object value, Type t, object parameter, CultureInfo culture) { return value.Equals(parameter); } public object ConvertBack(object value, Type t, object parameter, CultureInfo

How can you bind to a DynamicResource so you can use a Converter or StringFormat, etc.? (Revision 4)

被刻印的时光 ゝ 提交于 2019-12-17 07:15:16
问题 Note: This is a revision of an earlier design that had the limitation of not being usable in a style, negating its effectiveness quite a bit. However, this new version now works with styles , essentially letting you use it anywhere you can use a binding or a dynamic resource and get the expected results, making it immensely more useful. Technically, this isn't a question. It's a post showing a way I found to easily use converters with a DynamicResource as the source, but in order to follow s

How can you bind to a DynamicResource so you can use a Converter or StringFormat, etc.? (Revision 4)

笑着哭i 提交于 2019-12-17 07:15:08
问题 Note: This is a revision of an earlier design that had the limitation of not being usable in a style, negating its effectiveness quite a bit. However, this new version now works with styles , essentially letting you use it anywhere you can use a binding or a dynamic resource and get the expected results, making it immensely more useful. Technically, this isn't a question. It's a post showing a way I found to easily use converters with a DynamicResource as the source, but in order to follow s