我有一个IValueConverter,它的工作是将BlockId转换为ConditionLabel。问题在于,我的Model对象才具备实际转换的智能。到目前为止,我的代码看起来像这样...
public class BlockIdToConditionLabelConverter : IValueConverter
{
private Model _model;
public BlockIdToConditionLabelConverter(Model model)
{
_model = model;
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
int blockId = (int)value;
return _model.BlockIdToConditionLabel(blockId);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return Binding.DoNothing;
}
}
目前,我会在 ResourceDictionary 中创建一个静态资源(并在 DataTemplate 中引用它):
<local:BlockIdToConditionLabelConverter
x:Key="_blockIdToConditionLabelConverter" />
问题是,我需要一种方法将我的Model对象传递给这个转换器。我该如何做到这一点?
谢谢。