2013-05-15 53 views
0

,當我嘗試運行我的應用程序,我得到這個錯誤:「轉換器」不實現接口成員System.Windows.Data.IValueConverter.Convert

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

而且我Converter類這樣的:

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)  

回答

2

問題在於您的方法被命名爲convertMe而不是Convert(因此未成功實施IValueConverter)。更改爲:

public object Convert(... 
+0

感謝dbaseman,但即使我改變它,我仍然得到了同樣的錯誤:( –

+0

@HudaAhmed必須有一些錯誤的方法的簽名 - 如果你有Visual Studio中,您可以通過檢查這右鍵點擊'IValueConverter',它應該在那裏插入一個存根方法,你會看到不同之處 – McGarnagle

+1

@HudaAhmed請確保「相同的錯誤」真的是相同的錯誤,而不是另一個錯誤*同樣,但是抱怨不同的類型或不同的方法,請確保您的問題中的代碼與您的項目中的代碼相匹配,因爲此答案*應該*適用於您 – hvd

相關問題