Questions tagged [ivalueconverter]

IValueConverter is an interface defined in Microsoft .NET XAML for use in WPF, Silverlight and Xamarin.Forms. It is used in data binding to convert data from one format to another. The conversion can be one-way or bidirectional.

The .NET Binding classes have an optional Converter property of type IValueConverter which can be used to convert data from its native internal representation to something more convenient to a specific UI objective. A DateTime object could be converted to a string representation in a particular date/time display format, for example, or a numeric value could be converted to a color value for the background of a status control.

IValueConverter defines two methods: Convert and ConvertBack. Implement Convert to convert the source data to the display data representation. Implement ConvertBack to convert the display data representation to the source data representation. This is useful when the UI allows the user to edit the data. In the DateTime example above, if the display data were bound to a TextBox edit control (and the data binding Mode is set to TwoWay), the user could type in or change the date/time values. The IValueConverter specified on the data binding would be responsible for converting the text the user entered into a DateTime value in its ConvertBack method.

For more information, see the MSDN documentation on the IValueConverter interface.

668 questions
0
votes
1 answer

Add function to Convert function

I am trying to use Convert function from IValueConverter, but I have to call another function in it. I will use his return value but I got that error telling me to return an object value in the converter, any idea how can I avoid this please. public…
0
votes
1 answer

Datatrigger not firing when using a converter

I have a rectangle which I want to set 4 different icons to based on if a value inside my page.cs is between certain values, for instance: If value is 0 show icon 1. if value is larger than 0 but smaller or equal to 0.25 show icon 2. If value is…
Tokfrans
  • 1,939
  • 2
  • 24
  • 56
0
votes
1 answer

Binding ChildCollection to WPF DataGridColumn with IValueConverter

Ok so I have a WPF DataGrid bound to a collection of Products. The Product class has a property called ParentNumber and two navigation properties, Product Parent and ICollection SubProducts. I want to indicate in my DataGrid with a small…
Dux
  • 31
  • 4
0
votes
1 answer

DataGrid Converter is not called

I am trying to use an IValueConverter for a specific field in a DataGrid in my WPF project. What I find is that the converter is never called, even though the DataGrid is populated as data arrives. I have the following code:
user2434237
  • 21
  • 1
  • 5
0
votes
2 answers

Why is IValueConverter not called for DataGrid autogenerated Column

In an autogenerated datagrid column, I want to replace a certain value (-1) with blank. I created an IValueConverter: Public Class UsageConversion Implements IValueConverter Public…
GilShalit
  • 6,175
  • 9
  • 47
  • 68
0
votes
0 answers

Colorpleth value converter

I need to display data on a WPF application colored in proportion to the measurement of the item's property value, like on the image below. My question is how to provide the color/LinearGradientBrush (green-black-red) based on the relative value?…
Nuts
  • 2,755
  • 6
  • 33
  • 78
0
votes
1 answer

Why binding with converter changes properties not bound to on GUI?

I bound my text box to property (only text box) and used converter which just return opposite bool value. XAML
h__
  • 761
  • 3
  • 12
  • 41
0
votes
1 answer

IValueConverter - Casting generic Collections

I want to create a type independent Converter for counting the elements in a collection with a generic type. public class CollectionCountConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter,…
csc
  • 607
  • 1
  • 4
  • 15
0
votes
1 answer

IValueConverter is not working

I want create a user permission validation to my system, I have created a enum class Permission contained all type of permissions, example: CanInsert, CanEdit, CanAccess, CanDelete, etc... And in my class User has a property List contained all…
Lai32290
  • 8,062
  • 19
  • 65
  • 99
0
votes
1 answer

IValueConverter is only called first time databound TreeView is displayed

I have a TreeView that is bound to an ObservableCollection (that properly implements IPropertyNotifyChanged). Each TreeViewItem is a HierarchicalDataTemplate. I have a Converter on the TextBlock that is bound to 'amount' - that changes the…
Andy Powell
  • 583
  • 1
  • 6
  • 15
0
votes
1 answer

Make Binding/IValueConverter lower priority

I am displaying list of files and everything relies on Bindings and IValueConverters. The problem is that icons generate slowly as also some data like MP3's ID3 tags which I extract with IValueConverter supplying it with a path to song. Since I use…
Daniel
  • 1,064
  • 2
  • 13
  • 30
0
votes
1 answer

Value Converter not resolved in XAML class

I have a XAML file associated with a class that is not a UserControl descendant. I am trying to convert a string into a POCO using a value converter. This problem is I can't seem to get the converter to be picked up as a static resource. I get the…
Chris Gonzales
  • 1,180
  • 1
  • 13
  • 31
0
votes
2 answers

IValueConverter set new image

Hi to all out there... I facing one problem which is cannot set the new image: Does my code correct? public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var str =…
A-Max Lee
  • 27
  • 1
  • 10
0
votes
0 answers

Display a bound image in a ListView with multiple columns in C#

I have a short question about WPF and C#. Can somebody give me an example how the following xaml code would look in C# code? In xaml this works, but i would like to do some dynamic C# creation and need to do this in C# code as well. I am able to do…
stackr
  • 2,742
  • 27
  • 44
0
votes
0 answers

WPF use an outside IValueConverter in UserControl

I create a general-purpose UserControl which looks like a TickBar with labels shown below each tick. The UserControl is used to show timeline or map zoom scale and so on. The text shown in label is formatted according to the value (its type is…
user2606091
  • 203
  • 4
  • 9