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
0 answers

Databinding with Converters - Spooky behavior - Visual Studio 2012 .NET 4.5

So I have a combo box that loads its items from one sql table and then sets values in a second SQL table based on what you select. Now of course this couldn't be that simple, both tables AND the combo box all show different data. For…
DotNetRussell
  • 9,716
  • 10
  • 56
  • 111
0
votes
1 answer

Variable number of decimal places in Double to String ValueConverter

I created a ValueConverter between Double and String so that my textboxes have a given number of decimal places. I need, though, to be able to pass an integer as a parameter to the ValueConverter methods, so that I can have a different number of…
heltonbiker
  • 26,657
  • 28
  • 137
  • 252
0
votes
1 answer

Using EnvironmentColors.ToolWindowTextBrushKey in IValueConverter

I am setting foreground of a label control as below using EnvironmentColors class in XAML. Note that I am using BrushKey here.
0
votes
1 answer

IValueConverter, get other values of row in WPF DataGrid

I'm working on an C#/WPF project. I have a datagrid binded to a model. How can I get the other values of the same row available within the converter? Converter example: public object Convert(object value, Type targetType, object parameter,…
user2799180
  • 719
  • 1
  • 11
  • 29
0
votes
1 answer

Use IValueConverter within WPF DataGrid depending on several values of the same row

I'm working on a WPF project following the MVVM pattern. I do have the following Model: Name...¦.Value.¦.Unit.¦.Type.¦.Min.¦.Max.¦ Voltage¦.....3.....¦...mV..¦....X....¦...0...¦....5....¦ Current¦.....1.....¦...mA..¦....Y....¦...2...¦....7....¦ This…
user2799180
  • 719
  • 1
  • 11
  • 29
0
votes
2 answers

How to implement a NullableHasValueToBool IValueConverter

I'm trying to implement an IValueConverter which takes a nullable type e.g. int? Enum? etc. and returns a bool (true if it has a value, false otherwise). I don't know the type of nullable beforehand. The boxed value (of type object) does not have a…
Brendan
  • 18,771
  • 17
  • 83
  • 114
0
votes
1 answer

DomainDataSource - filtering on the client

What is the best way to filter a DomainDataSource(DDS) on the client? My DDS connects to the WCF Ria Service and downloads a number of items. I want to show bits of this information in different controls. eg a few ItemsControls showing items from…
Geoff Appleford
  • 18,538
  • 4
  • 62
  • 85
0
votes
2 answers

Checking if arbitrary enumerable has any items in without generics

So normally if you want to simply check if an IEnumerable has any items in you'd use .Any() instead of .count > 0 - especially when you're hitting things like LINQ-To-Entities and .count may have a heavy performance penalty. The problem I have is…
PhonicUK
  • 13,486
  • 4
  • 43
  • 62
0
votes
1 answer

Why isn't a property in my ViewModel updated when DataGrid changes?

I'm trying to create a UserControl, that will let me edit a Dictionary of type Dictionary in a grid (just editing entries so far, not adding or deleting). Whenever I bind the DataGrid to a Dictionary it shows the grid as read only, so…
Kyle Gobel
  • 5,530
  • 9
  • 45
  • 68
0
votes
0 answers

Binding when the Property is Vector3D, which is a struct

I'm trying to bind 3 TextBoxes (as a first step, but really 3 DataGrid columns) to components of a Vector3D property. Notice, though, that Vector3D is a struct and is thus value-type. The idea for the binding is to be able to edit a Vector3D…
New Dev
  • 48,427
  • 12
  • 87
  • 129
0
votes
1 answer

IValueConverter resource, namespace issue

I try to implement IValueConverter class and map it as resource in xaml file. In some reason im allways getting error "The name TypeConverter does not exist in the namespace clr-namespace:MyApp" But I can not find whats the issue there, my…
devha
  • 3,307
  • 4
  • 28
  • 52
0
votes
1 answer

x:Type in Windows Phone App

In a WPF Application I can use x:Type, e.g. for ConverterParameter:
Michael Giger
  • 125
  • 12
0
votes
1 answer

Only some Converters fire?

I am working on a project in WPF and I have a very strange case concerning my converters on a certain element. In the following snippet:
A.R.
  • 15,405
  • 19
  • 77
  • 123
0
votes
1 answer

IValueConverter and convert all values of bindinglist

I have a bindinglist with INotifyPropertyChanged interface. Things work fine. This bindinglist is a list of file names that is bound to a listbox. I want only the name displayed, not the whole path, but when I select a file name and load the file,…
Naresh
  • 633
  • 1
  • 7
  • 26
0
votes
2 answers

Resolve XAML Binding through Code on Windows Phone 8

I have a converter that provides a default value for empty strings. Apparently you can't add a binding to the ConverterParameter so I add a property to the converter, which I bind to instead. However, the value I'm getting back for the default…
Gavin
  • 5,629
  • 7
  • 44
  • 86