locked
Calling Lightswitch Screen Methods from Silverlight User Control RRS feed

  • Question

  • I need to call a method on the LS screen from a custom SL control.  I tried using the code from Michael Washington's Two Ways to Call Lightswitch from a custom Silverlight Control (after converting it to VB) but, for some reason, I get an error:

    Error    1    Default property access is ambiguous between the inherited interface members 'Public ReadOnly Default Property Item(name As String) As T' of interface 'Microsoft.LightSwitch.Details.IDetailsSet(Of Microsoft.LightSwitch.Details.Client.IScreenMethod)' and 'Public ReadOnly Default Property Item(name As String) As Microsoft.LightSwitch.Details.IDetailsWithName' of interface 'Microsoft.LightSwitch.Details.IDetailsSet'.    C:\DATA\VB.NET\BRS1\MapControl\gpTools.xaml.vb    80    51    MapControl

    The code-behind looks like this:

    Imports Microsoft.LightSwitch.Presentation

    Partial Public Class gpTools
        Inherits UserControl

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub CallLSMethod_Click(sender As Object, e As RoutedEventArgs)
            ' Get a reference to the LightSwitch DataContext
            Dim objDataContext = DirectCast(Me.DataContext, IContentItem)

            ' Get a reference to the LightSwitch Screen
            Dim Screen = DirectCast(objDataContext.Screen, Microsoft.LightSwitch.Client.IScreenObject)

            ' Call the Method on the LightSwitch screen
            Screen.Details.Dispatcher.BeginInvoke(Function()
                                                      Screen.Details.Methods("MyLSMethod").CreateInvocation(Nothing).Execute()
                                                  End Function)
        End Sub

    End Class

    Any idea how to make this work?

    Thanks in advance for your contribution!!


    Isahak


    • Edited by Isahak Thursday, July 2, 2015 9:30 PM
    Thursday, July 2, 2015 9:13 PM

Answers

  • Found the answer in Tim Leung's book, VS Lightswitch 2012!

    The last lines of code above are incorrect.  This syntax works:

    ' Call the method on the LightSwitch screen

    Screen.Details.Dispatcher.BeginInvoke(

    Sub()

    Screen.Details.Commands.Item("MyLSMethod").Execute()

    End Sub)


    Isahak

    • Marked as answer by Angie Xu Thursday, July 16, 2015 1:59 AM
    Monday, July 6, 2015 9:48 PM