valueconverter

dynamic datatemplate with valueconverter

I want to show data in a wpftoolkit datagrid where the data is a collection of public class Thing { public string Foo { get; set; } public string Bar { get; set; } public List<Candidate> Candidates { get; set; } } public class Candidate { public string Name { get; set; } public CandidateType CandidateType { get; se...

WPF : An alternative way to specify a ValueConverter on binding

Most common way I encountered of specifying a value converter for a binding is to: 1. Create an instance of the value converter as a resource with a key. 2. Reference the instance using StaticResource markup extension: <TextBlock Text="{Binding Converter={StaticResource myFormatter}" /> Q: Is there anything wrong with using static ins...

Creating a WPF ValueConverter for a Brush

On the Nerd Plus Art blog today, there was a post about creating WPF Resources for arrows, which the author uses frequently. I have a side project that has Back and Forward buttons, so I thought that the Left and Right arrows would work great on those buttons. I added the LeftArrow and RightArrow Geometries to my application's resources...

Should your ViewModel expose XAML elements as properties or not?

Over at the StackOverflow question How can WPF Converters be used in an MVVM pattern? I've learned that Value Converters should not be used in the MVVM pattern since the functionality of a Value Converter should be handled by the ViewModel itself. This makes sense. But I remember reading that you should not expose XAML elements to the ...

My databinding with value converter does not work

I've got a simple Item-class, that looks like this: public class Item : DependencyObject { public int No { get { return (int)GetValue(NoProperty); } set { SetValue(NoProperty, value); } } public string Name { get { return (string)GetValue(NameProperty); } set { SetValue(NameProperty, value); } } public static readonly D...

Anything similar to WPF's ValueConverters for ASP.Net ?

After doing a project with WPF and getting very much attached to it's excellent databinding capabilities, I have now moved back to ASP.Net and am starting to miss some of WPF's stuff. My question is...is there anything similar to WPF's ValueConverters for ASP.Net? For example, I want a UserControl to expose a public property which is a...

WPF : Control Binding - Trigger IValueConverter from C# code

In my XAML Code I have bound the Height property of an control to the ActualHeight for it's parent control. Because I have to calculate an offset from the original value I use and IValueConverter. Height="{Binding ElementName=MainCanvas, Path=ActualHeight, Converter={StaticResource adjustVerteilung} , ConverterParameter= 12}" This wor...

What's a good way to parameterize a ValueConverter used in a ControlTemplate?

A templated control I'm working on uses a ValueConverter like so: <ListBox> <ListBox.Resources> <Controls:CodeDescriptionValueConverter x:Key="CodeDescriptionValueConverter"/> </ListBox.Resources> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Converter={StaticResource CodeDescriptionValueC...

INotifyPropertyChange does not update converter-based values?

I have an image with source set by a ValueConverter. When the bound object raises a ProprtyChanged event (from INotifyPropertyChanged), the image does not change. I assume it is because WPF doesn't know what fields the converter looks at. How do I tell WPF to rebind/rerun this converter when a certain property changes? ...

Intercept Silverlight DatePicker's convert from text to DateTime

Hi, I want DatePicker to convert the following text pieces to DateTime (shown in international format) so my customers can write a date in DatePickers textbox faster so it is not just DateTime.Parse I will use: "3" to 2009-10-03 "14" to 2009-10-14 "1403" to 2009-03-14 "140310" to 2010-03-14 "14032010" to 2010-03-14 I have tried diffe...

WPF binding to another property's binding in a style

I'm not sure the best way to ask this question (sorry for the ambiguous question title), but essentially I'd like to set the MaxLength property on a TextBox using a value converter that is passed in a property from the data context, and the property on the passed-in property as the converter parameter. I'd like to do all this in a style,...

Displaying a custom value type in WPF without using a Value Converter

The system I'm working on uses a large number of custom value types internally. I'm working on a prototype UI using WPF. WPF does not know how to display the custom types. I know that I can write a custom ValueConverter to do this, but I really don't want to have to specify the use of a converter every time I bind to a class in my XAM...

When to use value converters in a mvvm application?

Hi! If one is implementing a WPF application using the MVVM design pattern, is there any situation in which to use value converters? It seems to me that value converters do exactly the same what the view model does too, that is preparing data for the view. So, are there some good uses for value converters? Best Regards Oliver Hanappi ...

WPF Value Converter Trigger Reconvertion at custom event?

Is there any way to force wpf to run the value converter again on a specific event? ...

IDataErrorInfo with ValueConverter

I'm somehow doing it wrong, but I can't figure it out: I have a model like this: public class Person : IDataErrorInfo { public DateTime Birthdate { get { return _birthdate; } set { if (!Valid(value)) AddError("Birthdate", "Birthdate not valid"); _birthdate = value; } } } A ValueConverter like this...

Is using value converters to generate GUI-friendly strings a misuse of value converters?

Currently, I use value converters to generate user-friendly strings for the GUI. As an example, I have a window that displays the number of available entities in the status bar. The Viewmodel simply has an int dependency property that the calling code can set, and then on the binding for the textbox that displays the number of entities...

wpf converter in xaml

Hi, I know there are a few ways to use value converter in xaml, like using StaticResource to get converter from resources or Static to get from a static instance. My question is, for whatever reason, I have a converter instance created in the code behind, and can be accessed through a non static property, How can I use this instance of ...

Updating an Observable Collection Based on a combobox selection...

So I have an ObservableCollection of items called "Class1" and Class1 has a property named "ID". I use a datagrid from the WPFToolkit and bind to this collection. Within the datagrid is a combobox column and I bind it's ItemsSource to the ID property of the class. At this point, all is good and everything populates as it should. What ...

How to bind a ConvertorParameter

Hi all, I am trying to bind the value of a ConverterParameter. Currently finding it too tricky... Codebehind public static readonly DependencyProperty RecognitionProperty = DependencyProperty.Register("RecognitionToEdit", typeof(Recognition), typeof(RecognitionInstancesWindow), null); public Recognition Recognition { ...