Code Conversion from C# to VB.NET ends with a not useable code

2 posts, 0 answers
  1. Harald Bacik
    Harald Bacik avatar
    13 posts
    Member since:
    Aug 2009

    Posted 28 Oct 2011 Link to this post

    I try to convert the following code from C# to VB.NET
    public static class Navigator
           public static INavigable GetSource(DependencyObject obj)
               return (INavigable)obj.GetValue(SourceProperty);
           public static void SetSource(DependencyObject obj, INavigable value)
               obj.SetValue(SourceProperty, value);
           public static readonly DependencyProperty SourceProperty =
                DependencyProperty.RegisterAttached("Source", typeof(INavigable), typeof(Navigator), new PropertyMetadata(OnSourceChanged));
           private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
               Page page = (Page)d;
               page.Loaded += PageLoaded;
           private static void PageLoaded(object sender, RoutedEventArgs e)
               Page page = (Page)sender;
               INavigable navSource = GetSource(page);
               if (navSource != null)
                   navSource.NavigationService = new NavigationService(page.NavigationService);

    This ends with a code conversion, which is not useable in VB.NET because the DependencyProperty is "new PropertyMetaData(OnSourceChanged) can't be executed in VB.NET but an AddHandler does not solve the problem, because the VB.NET translated code doesn n ot fire "OnSourceChanged"


  2. Todd
    Todd avatar
    66 posts

    Posted 04 Nov 2011 Link to this post

    Hello Harald,

    Sorry for the trouble with this conversion. I don't think the underlying NRefactory conversion engine handle DependencyProperties perfectly, so this is a limit of the current version. We'll investigate options for improving the conversion in the future.

    In the meantime, thanks for highlighting the problem and the workaround solution!

Back to Top