0

当我尝试运行我的应用程序时出现此错误:

'InsightSplash.theMenuConverter' 没有实现接口成员 'System.Windows.Data.IValueConverter.Convert(object, System.Type, object, System.Globalization.CultureInfo)'

知道这有什么问题吗?据我所知,我的进口是正确的:

我的 Xaml 界面:

<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>

我的转换器类是这样的:

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;
    }
}

我拥有的数据库是

活动权限表
=====================
ActivePermID bigint  
权限ID int
用户 ID 整数
页面活动位

权限表
===============
权限ID int
权限描述 nvarchar(30)    

4

1 回答 1

2

问题只是您的方法被命名convertMe而不是Convert(因此没有成功实现IValueConverter)。改成:

public object Convert(...
于 2013-05-15T21:29:22.877 回答