I have this situation: I've an enum and I'm creating a datagrid composed of rows based on each value of this enum.
I'm passing enum values as strings to some customized converters and it's working fine.
However I reach a situation where I would like, with a converter, to return an object and bind it's property, not the object itself. Actually I'm doing this through the converter parameter, but the problem is that with the designer this thing doesn't work.
Here are some pieces of code:
XAML:
<DataGridTextColumn Header="Comments" Binding="{Binding Converter={specializedconverters:ButtonToButtonMacroConverter}, ConverterParameter=Comments, Mode=OneWay}" Width="*" />
Converter:
[ValueConversion(typeof(string), typeof(object))]
internal class ButtonToButtonMacroConverter : BaseConverter, IValueConverter
{
public ButtonToButtonMacroConverter() { }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if ((bool)DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof(DependencyObject)).DefaultValue)
return "Data visible only at runtime";
ButtonMacro macro = CurrentProfile.Profile.GetMacro((Buttons)Enum.Parse(typeof(Buttons), value as string));
return macro.GetType().GetProperty(parameter as string).GetValue(macro, null);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
What I would like to know is if there is a better way to do this and see it at design time too. I would like to return through the converter the object itself (ButtonMacro) and access it's property in the binding, something like Path=Comments (which is a property of ButtonMacro)
Example:
<DataGridTextColumn Header="Comments" Binding="{Binding Converter={specializedconverters:ButtonToButtonMacroConverter}, Path=Comments, Mode=OneWay}" Width="*" />
Is something like this possible?
Update 1:
<TextBlock Text="{Binding Source={Binding Converter={specializedconverters:ButtonToButtonMacroConverter}, Mode=OneWay}, Converter={converters:ObjectToStringConverter}}" />
Is possible to do something like this?