'Converter'没有实现接口成员System.Windows.Data.IValueConverter.Convert

时间:2013-05-15 21:28:04

标签: c# wpf ivalueconverter

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

  

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

我的数据库是


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

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

1 个答案:

答案 0 :(得分:2)

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

public object Convert(...