This is a migrated thread and some comments may be shown as answers.

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

1 Answer 111 Views
Code Converter
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Harald Bacik
Top achievements
Rank 2
Harald Bacik asked on 28 Oct 2011, 10:09 AM
Hey
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"

THX


1 Answer, 1 is accepted

Sort by
0
Todd
Telerik team
answered on 04 Nov 2011, 10:28 PM
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!

-Todd
Tags
Code Converter
Asked by
Harald Bacik
Top achievements
Rank 2
Answers by
Todd
Telerik team
Share this question
or