0

I got this error when I try to run my application:

'InsightSplash.theMenuConverter' does not implement interface member 'System.Windows.Data.IValueConverter.Convert(object, System.Type, object, System.Globalization.CultureInfo)'

Any idea what's wrong with this? As far as I know my imports are correct:

My Xaml Interface :

<Window x:Class="InsightSplash.Window2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:local="clr-namespace:InsightSplash" 
    Title="Window2" Height="300" Width="300" Loaded="Window_Loaded">
<Window.Resources>
    <local:theConverter x:Key="theConverter"/>
    <Style TargetType="{x:Type MenuItem}">
        <Setter Property="IsEnabled" Value="{Binding RelativeSource={RelativeSource Self}, 
            Converter={StaticResource theConverter}}"></Setter>
    </Style>
</Window.Resources>
<Grid HorizontalAlignment="Left" VerticalAlignment="Top" >
    <Menu Grid.Row="0" Width="100" Height="30" IsMainMenu="True">
        <MenuItem x:Name="Menu0" Header="الموارد البشرية" IsEnabled="True" >
            <MenuItem x:Name="Menu1" Header="الادارات الرئيسية"></MenuItem>
            <MenuItem x:Name="Menu2" Header="الموظفين"></MenuItem>
        </MenuItem>
    </Menu>
</Grid>

And My Converter class like that:

public class theMenuConverter : IValueConverter
{
    DataClasses1DataContext dbusers = new DataClasses1DataContext();

    public object convertMe(object value, Type targetType, object parameter, CultureInfo culture)
    {
        MenuItem mi = (MenuItem)value;

        string header = mi.Header.ToString();

        int userID = AFunctionToGetAUser();

        int? permissionID = (from permsion in dbusers.PermissionsTbls
                           where permsion.PermissionDescription == header
                           select permsion.PermissionID).SingleOrDefault();

        bool? pageActivity = (from active in dbusers.ActivePermissionsTbls
                           where active.PermissionID == permissionID && active.UserID == userID
                           select active.PageActive).SingleOrDefault();


        if (pageActivity == true && header != null)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }

    private int AFunctionToGetAUser()
    {

        return 1;
    }
}

My database which I have is


ActivePermissionsTbl
====================
ActivePermID    bigint  
PermissionID    int 
UserID          int 
PageActive  bit 

PermissionsTbl
==============
PermissionID            int 
PermissionDescription   nvarchar(30)    

McGarnagle
  • 101,349
  • 31
  • 229
  • 260
Huda Ahmed
  • 27
  • 6

1 Answers1

2

The problem is just that your method is named convertMe instead of Convert (hence does not successfully implement IValueConverter). Change to:

public object Convert(...
McGarnagle
  • 101,349
  • 31
  • 229
  • 260
  • thanks dbaseman, but even after I changed it I still got same error :( – Huda Ahmed May 15 '13 at 21:35
  • @HudaAhmed there must be something wrong with the method's signature -- if you have Visual Studio, you can check this by right-clicking on `IValueConverter`. It should insert a stub method there, and you'll see the difference. – McGarnagle May 15 '13 at 21:39
  • 1
    @HudaAhmed Please make sure "same error" really is the same error, and not another error that is *almost* the same, but complains about a different type or a different method. Please also make sure that the code in your question matches what you've got in your project. Because this answer *should* work for you. –  May 15 '13 at 21:39
  • 2
    How is the resource using InsightSplash.theConverter but the class you displayed called theMenuConverter? – Rich May 15 '13 at 21:41
  • 1
    Thanks , I checked it again & worked fine now. i appreciated your help – Huda Ahmed May 15 '13 at 21:44