メソッドの出力にバインドしようとしています。これを使用した例を見てきましたが、これに関するObjectDataProvider
問題は、ObjectDataProviderがメソッドを呼び出すオブジェクトの新しいインスタンスを作成することです。現在のオブジェクトインスタンスで呼び出されるメソッドが必要な場合。私は現在、コンバーターを動作させようとしています。
設定:
Class Entity
{
private Dictionary<String, Object> properties;
public object getProperty(string property)
{
//error checking and what not performed here
return this.properties[property];
}
}
XAMLでの私の試み
<local:PropertyConverter x:Key="myPropertyConverter"/>
<TextBlock Name="textBox2">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource myPropertyConverter}"
ConverterParameter="Image" >
<Binding Path="RelativeSource.Self" /> <!--this doesnt work-->
</MultiBinding>
</TextBlock.Text>
</TextBlock>
背後にある私のコード
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
string param = (string)parameter;
var methodInfo = values[0].GetType().GetMethod("getProperty", new Type[0]);
if (methodInfo == null)
return null;
return methodInfo.Invoke(values[0], new string[] { param });
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotSupportedException("PropertyConverter can only be used for one way conversion.");
}
私の問題は、現在のエンティティをコンバータに渡すことができないように見えることです。したがって、リフレクションを使用してgetPropertyメソッドを取得しようとすると、操作するものが何もありません。
ありがとう、ステフ