No, you cannot bind to the extension method. You can bind to the Dog object's Name -property and use the converter though.
To create a converter, create a class that implements the IValueConverter interface. You only need a one-way conversion (from model to view), so you only need to implement the Convert method. The ConvertBack method ConvertBack not supported by your converter and thus throws a NotSupportedException .
public class NameToBarkConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var dog = value as Dog; if (dog != null) { return dog.BarkYourName(); } return value.ToString(); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotSupportedException(); } }
Then you can use your converter as follows:
<Grid> <Grid.Resources> <NameToBarkConverter x:Key="NameToBarkConverter" /> </Grid.Resources> <TextBlock Text="{Binding Name, Converter={StaticResource NameToBarkConverter}}" /> </Grid>
For more information about converters, see MSDN: IValueConverter .
source share