I’m trying to convert the following C# code to VB. The reults from online conversion pages I have tried doesn’t make sense to me and VS2010 marks them as flawed. My limited C# knowledge about events isn’t enough to solve this one…
The MVVM sample uses this interface:
public interface IRequestCloseViewModel
{
event EventHandler RequestClose
}
And it is used in this base class:
public class ApplicationWindowBase : Window
{
public ApplicationWindowBase()
{
this.DataContextChanged += new DependencyPropertyChangedEventHandler(this.OnDataContextChanged);
}
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue is IRequestCloseViewModel)
{
// if the new datacontext supports the IRequestCloseViewModel we can use
// the event to be notified when the associated viewmodel wants to close
// the window
((IRequestCloseViewModel)e.NewValue).RequestClose += (s, e) => this.Close();
}
}
}
What would the correct VB .NET translation look like?
This should do it for you: