ivalueconverter

Databinding on a IValueConverter

Does anybody know if it is possible to do databinding on an IValueConverter based class? I have the following converter: [ValueConversion(typeof(int), typeof(Article))] public class LookupArticleConverter : FrameworkElement, IValueConverter { public static readonly DependencyProperty ArticlesProperty = DependencyProperty.Register("...

WPF: Listbox, valueconverter

What is the easiest way to use a valueconverter with a listbox? I'm setting the ItemSource to a List<> of objects at runtime, and it displays a textstring from the ToString() method. What I would like, though, is to pass the object through a valueconverter to get a completely different string value. All the examples I have found makes ...

Getting a reference to the ViewModel from an IValueConverter

Is there a clean and/or an accepted standard way of referring back to the ViewModel from an IValueConverter, or does that break the MVVM pattern? Basically, I want to convert bound data in the UI based on other properties of the ViewModel. I guess this is the same question as how do you refer back to the Window/Page from an IValueConve...

WPF - DataTemplate/Value Converter for hyperlink in TextBlock

I have a ListBox showing a list of people's names, emails, departments, etc. There is a DataTemplate that has a few TextBlocks to display each property. One of these TextBlocks is wrapping a Hyperlink to show email addresses like so: <TextBlock> <Hyperlink NavigateUri="{Binding Email}"> <TextBlock Text="{Binding Email}" /> <...

Pass value of a field to Silverlight ConverterParameter

Hi all, I'm writing my very first Silverlight app. I have a datagrid with a column that has two labels, for the labels, i am using an IValueConverter to conditionally format the data. The label's "Content" is set as such: Content="{Binding HomeScore, Converter={StaticResource fmtshs}}" and Content="{Binding AwayScore, Converter={...

Silverlight: Conditional Formatting based on Multiple Fields

Okay, still on my silverlight app here, what I need to do is to somehow perform conditional formatting on the cells of a datagrid, but the "conditional" part needs to be based upon the values of several different fields/properties in the datasource. I thought i could use the typical IValueConverter method of conditional formatting and ...

DataBinding in a DataTemplate using custom IValueConverter disappearing mysteriously

I have a bunch of custom classes (NumericTextBox and NumericConverter in this case) which I used successfully without any warning or error for a while. Now I just hit a problem where if I use the converter in the binding on the NumericTextBox inside a DataTemplate, the binding is broken. But if I use just the NumericTextBox or just the N...

Silverlight Update/Trigger IValueConverter in Listbox DataTemplate in a DataGrid

Hi I am building an application to display a datagrid bound to an ObservableCollection of Records, where each record has a Course Object and an ObservableCollection of Results Objects. The course is changed using an autocomplete box. The results collection is displayed in a Listbox with an IValueConverter implementation to change the c...

WPF and MVVM: Changing data binding converter at runtime

I am using WPF and the MVVM pattern in my user interface. In my ViewModel I have a List containing distances in millimetres, which I display in a ListView by binding ListView.ItemsSource to the List. However, I would like the values displayed to use a more natural unit - either metres or feet depending on the state of a "metric" checkbox...

wpf datagrid observablecollection

Im working on a large database application using WPF. So far, I was able to create a DataContext using Link to Sql class, store it in an ObservableCollection, and fed it to my DataGrid as DataContext. The main table in SQL I'm trying to read/write looks like this Work_Table WorkID[pk int] | frn_CustomerID[fk int] | frn_UserID[fk int] |...

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 the DDS filtered by various values. I know I could create a new DDS for each control and fi...

Simple WPF IValueConverter and DataTrigger not working together

I've been having trouble using a value converter with a data trigger. In some of my code it seems like the DataTrigger's Path is being applied to the root element, rather than the element which the style applies to. I created a simple test case, and I don't understand its behavior. I'm expecting the Button to turn red or blue depending ...

M-V-VM WPF: Way to maintain Databinding while passing parent object of Databound object into IValueConverter?

I'm using model-view-viewmodel I currently have a class with 3 pieces of data: 2 integers and an enumeration. Its constructor looks like this: //C# public Outcome(OutcomeEnum outcomeEnum, Int32 acutalOutcomeData, Int32 expectedOutcomeData) { m_outcomeEnum = outcomeEnum; m_actualData = acutalOutcomeData; m_expectedData = expected...

Having an issue with CoverterParameter Binding in silverlight

Hi everyone, I am having an issue with the xaml parser not liking my binding statement but i cannot see anything wrong with the statement. Invalid attribute value {Binding VehicleSpeed, ConverterParameter={Binding InMiles}, Converter={StaticResource SpeedConverter}, Mode=TwoWay} for property DataMemberBinding VehicleSpeed and InMi...

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...

How to use MultiBinding in a WPF ComboBox

This is driving me NUTS!!! I have a ComboBox used to filter a query by employee which works fine but only displays the employees first name. I want to use a MultiValueConverter to display the employees full name (This would be less urgent if we did not have 2 Mikes and 2 Daves) Below is my working code and the IMultiValueConverter Clas...

InvalidCastException in converter

This is my class that implements IValueConverter: [ValueConversion(typeof(int), typeof(Priority))] public class PriorityConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return (Priority) (int) value; } ...

IValueCOnverter Not Working

Hi There, Been googling this problem for hours, and cannot see where I am going wrong. I have the following converter which just returns Brushes.Red(have tried Colors.Red) as well but still no luck. public class ColorConverter : IValueConverter { private static ColorConverter instance = new ColorConverter(); public static Colo...

Why would putting a no-op Converter on a Binding change its behavior?

I'm in the midst of testing a user control I've built, and I'm encountering something that's inexplicable to me. The control's an extension of the ComboBox that handles values of a specific custom type. It has a dependency property of that custom type that is the target property of a Binding. I've got a trace statement in the setter...

Errors during value conversion

When creating a custom IValueConverter for a user-editable field, the Convert implementation is usually fairly straightforward. The ConvertBack implementation is not, since (in the absence of an explicit validation rule) it has to cope with bad user input (eg. typing "hi" in a numeric input field). If an error occurs during conversion,...