locked
Silverlight Training Course (Silverlight 4) Question RRS feed

  • Question

  • Hi, I'm going through this course but trying to make it in VB. I have no idea how to make the following C# statement into VB. No C# to VB conversion tool makes a successful effort, so any clues would be greatly appreciated: WebContext.Current.Authentication.LoggedIn += Function(s, e) UpdateForUserRole()
    Tuesday, June 8, 2010 12:04 PM

Answers

  • No help was forthcoming so it's fairly pointless keeping this open

    Wednesday, July 21, 2010 9:04 AM

All replies

  • This is a handler. Lookup event handlers, inline event handlers, handlers, for VB.NET for more info.

    You can try:

    AddHandler WebContext.Current.Authentication.LoggedIn, AddressOf Authentication_LoggedIn

    And then you can create the function.. 'Authentication_LoggedIn'
     

    Or for similar inline handling like the above you can do something like:

    AddHandler WebContext.Current.Authentication.LoggedIn,
    Sub (ByVal s As Object, ByVal e As ApplicationServices.AuthenticationEventArgs)     

         If e.Result <> Nothing Then

            UpdateForUserRole

         End If

    End Sub
    Tuesday, June 8, 2010 1:22 PM
  • Thanks for this. I had created a handler but could not obtain the same outcome as the C# code. The constructor is as follows: public HomeViewModel() { _registerCommand = new RelayCommand(OnRegister); _unregisterCommand = new RelayCommand(OnUnregister); WebContext.Current.Authentication.LoggedIn += (s, e) => UpdateForUserRole(); WebContext.Current.Authentication.LoggedOut += (s, e) => UpdateForUserRole(); UpdateForUserRole(); } and the UpdateForUserRole is: private void UpdateForUserRole() { bool isLoggedIn = WebContext.Current.User.IsAuthenticated; bool isAdmin = isLoggedIn && WebContext.Current.User.IsInRole("Event Administrators"); AdminButtonsVisibility = isAdmin ? Visibility.Visible : Visibility.Collapsed; AttendeeButtonsVisibility = (isLoggedIn && !isAdmin) ? Visibility.Visible : Visibility.Collapsed; if (isLoggedIn) { var ctx = new EventManagerDomainContext(); ctx.FetchEventsForWhichCurrentUserIsRegistered((op) => { if (!op.HasError) { var items = op.Value; _currentUserRegisteredEventIds = new HashSet(items); UpdateRegistrationButtons(); } }, null); } else { _currentUserRegisteredEventIds = null; UpdateRegistrationButtons(); } }
    Tuesday, June 8, 2010 1:58 PM
  • Hi,

    Please format the code, it's hard to read. When you post code, please select the "Source Code" icon on the toolbar, then you can paste the code and select correct language:)

    Above post already shows you how to add a handler in VB.NET. Since you said that you created a handler but could not obtain the same result, could you please show us how you do it in VB.NET so that we can check if there's any problem in your code? Thanks.

    Friday, June 11, 2010 1:22 AM
  • Hi Frank,

    Thanks for this - I used Quick Reply so the code wasn't formatted. The code is simply the C# code from the Lab sample, put through Telerik conversion engine and with the "Do" statement removed - here it is properly!

    1                If isLoggedIn Then
    2                    Dim
    ctx = New EventManagerDomainContext()
    3                    ctx.FetchEventsForWhichCurrentUserIsRegistered(Function(op)
    4                                                                       If Not op.HasError Then
    5                                                                           Dim
    items = op.Value
    6                                                                           _currentUserRegisteredEventIds = New HashSet(Of Integer)(items)
    7                                                                           UpdateRegistrationButtons()
    8                                                                       End If
    9                                                                   End Function
    , Nothing)
    10               Else
    11                   _currentUserRegisteredEventIds = Nothing
    12                   UpdateRegistrationButtons()
    13               End If

      
    Friday, June 11, 2010 4:47 AM
  • No help was forthcoming so it's fairly pointless keeping this open

    Wednesday, July 21, 2010 9:04 AM