0

I'm currently learning UWP on the Microsoft Virtual Academy. Right now I'm on a challenge regarding adaptivity / binding. The course is taught in C# so I have to translate the C# code to vb.net, since this is the language I learned earlier. Not a huge deal until now:

When creating a UserControl that is to be put into a GridView, I am asked to put this line of Code after InitializeComponent().

this.DataContextChanged += (s, e) => Bindings.Update();

Unfortunately, I have no idea how to translate this expression into Visual Basic. Any help would be greatly appreciated!

The solution Code can be found at 2:42 here.

The challange video can be found here.

Felix
  • 3
  • 1
  • 1
    [This](https://stackoverflow.com/questions/18317333/how-to-write-a-vb-net-lambda-expression) is how you write an expression in VB.NET. – Dmitry Volkov Jun 16 '17 at 20:23

1 Answers1

1

Try this:

AddHandler Me.DataContextChanged, Sub(ss As FrameworkElement, ee As DataContextChangedEventArgs)
                                      Bindings.Update()
                                  End Sub
mm8
  • 163,881
  • 10
  • 57
  • 88
  • Thank you for your hint. Right now, though, i get: "'Bindings' is not declared. It may be inaccessible due to ist protection Level.". – Felix Jun 16 '17 at 21:13
  • VB also lets you omit the lambda parameter types if you wish: e.g., Sub(s, e) Bindings.Update() – Dave Doknjas Jun 16 '17 at 21:13
  • 1
    @Cineas: Actually the Bindings object should be created automatically for you if you actually use the {x:Bind} markup extension in your XAML view. You need to add the XAML markup in NewsItemsControl.xaml before you can call Bindings.Update(). – mm8 Jun 16 '17 at 21:35
  • Thanks for your help so far! Unfortunately, it did not create the the Bindings object. I have multiple {x:Bind}s in my NewsItemsControl.xaml. Im currently trying to reproduce the error in a new project. – Felix Jun 16 '17 at 21:49
  • Try to build the project and then add the call to the Bindings.Update method. It certainly works for me. – mm8 Jun 16 '17 at 21:52
  • Allright! I got Bindings.Update() now! Thanks a lot! Still don't know how i would raise the DataContextChanged Event, tho. Does AddHandler do that? Cuz my UserControl still doesn't show up in the GridView. :( – Felix Jun 16 '17 at 22:05