I am having problems using a binding converter written in code-behind, with the corresponding markup. It keeps giving me the same error:
does not implement interface member 'System.Windows.Data.IValueConverter.Convert(object, System.Type, object, System.Globalization.CultureInfo)'
When I see nothing wrong with the code. I am trying to set-up a DataTemplate for a listbox which has a DataContext set when page is loaded. Here is some partial code from my application
Code Behind:
namespace Financial_Manager
{
public class AmountOnScreenConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return "£" + Math.Round((decimal)value, 2).ToString();
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}
Xaml: (local corresponds to the namespace Financial_Manager)
<Page.Resources>
<local:AmountOnScreenConverter x:Key="amountConvert" />
<DataTemplate x:Key="recordTemplate">
<Grid Name="newElement">
<TextBlock Name="txtAmount" Height="17" Width="70" Text="{Binding Path=Amount, Mode=OneWay, Converter={StaticResource amountConvert}}"/>
</Grid>
</DataTemplate>
</Page.Resources>
I've looked around and cant seem to find any reason why this error should be showing. If I move converter outside of namespace, this error no longer exists, but I can't access converter in mark-up.
Does anyone have any suggestions?
Update: I have now got visual studio to accept my code as correct, but had to move converter into its own namespace. Don't understand why this had to be done though..