Reputation: 27
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)
Upvotes: 0
Views: 2064
Reputation: 102753
The problem is just that your method is named convertMe
instead of Convert
(hence does not successfully implement IValueConverter
). Change to:
public object Convert(...
Upvotes: 2