문제

So I have an object with multiple attributes that I have bound to my GUI using WPF. Most of the GUI binds directly to properties in my object instance. Some of the GUI elements need to be processed via a ValueConverter first however, as they rely indirectly on an attribute in the bound object. I can create the valueconverter, but was uncertain how to reference the databound object in order to pull the right property values for the conversion.

In pseudo-code I want to do this:

public object Convert(object value, Type targetType, object parameter,
    System.Globalization.CultureInfo culture)
{
    parameter = Databoundobject.EngineRating;
    double weight = EngineList.selfInstance.WeightList[parameter];
} 

I can find examples that don't reference a databound source in the calling gui, but none that do. Does anyone know how I can accomplish this?

도움이 되었습니까?

해결책

The value parameter in the Convert() method will hold that raw value from the data-bound source.

Therefore, if you use the converter in a binding to the EngineRating property, value will hold the value you're looking for. (You'll need to cast it back to the original type)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top