Hi I am right now in an project using VB.NET and needs to translate this C# code into VB.NET
oldCommand.CanExecuteChanged -= commandReference.CanExecuteChanged;
newCommand.CanExecuteChanged += commandReference.CanExecuteChanged;
For me it seems like the an event hooking up on an another event? But I have tried everything to translate this into VB.NET code? I have found out that EventHandler management in VB.NET is far from as good it is in C# as many other things.
So how can I do this in VB.NET?
Edit: here is the code I want to transalate all code is easy to translate but the code in the method OnCommandChanged.
public class CommandReference : Freezable, ICommand
{
public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command",
typeof(ICommand),
typeof(CommandReference),
new PropertyMetadata(new PropertyChangedCallback(OnCommandChanged)));
public ICommand Command
{
get { return (ICommand)GetValue(CommandProperty); }
set { SetValue(CommandProperty, value); }
}
#region ICommand Members
public bool CanExecute(object parameter)
{
if (Command != null)
return Command.CanExecute(parameter);
return false;
}
public void Execute(object parameter)
{
Command.Execute(parameter);
}
public event EventHandler CanExecuteChanged;
private static void OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
CommandReference commandReference = d as CommandReference;
ICommand oldCommand = e.OldValue as ICommand;
ICommand newCommand = e.NewValue as ICommand;
if (oldCommand != null)
{
oldCommand.CanExecuteChanged -= commandReference.CanExecuteChanged;
}
if (newCommand != null)
{
newCommand.CanExecuteChanged += commandReference.CanExecuteChanged;
}
}
#endregion
#region Freezable
protected override Freezable CreateInstanceCore()
{
throw new NotImplementedException();
}
#endregion
}