Silverlight – Silverlight plugin installed but not recognized as installed

This issue relates to Internet Explorer only. This problem does not affect Chrome or Firefox.

First, try this:

http://support.microsoft.com/kb/2608523

If that does not work or you get an error stating permission issues with AgControl.AgControl, then try this:

1. Run regedit (start->run->regedit)

2. Navigate to HKEY_CLASSES_ROOTAgControl.AgControl (if you get a message that says “AgControl.AgControl cannot be opened. An error is preventing this key from being opened. Details: Access is denied.” proceed to the “Taking ownership
of the key” section)

3. Right click and choose “Permissions”

4. Click “Add”

5. Either add your windows username or your network username in the the “Enter the object names to select” and click “Check Names”. Your name should take the proper format. If it does not try clicking “Advanced” and searching for your
username. My windows username was the one I used.

6. Click OK

7. Select your new username in the top pane and in the lower pane (Permissions for ) check the Allow box next to Read.

8. Click OK

Check Silverlight installation in IE by going to http://www.silverlight.net/

Taking ownership of the key (If you’re getting access denied errors while trying to set permissions)

You can download the following tool from microsoft to open an

instance of regedit as system:

http://technet.microsoft.com/en-us/sysinternals/bb897553

The following command line will open a “system” regedit:

 psexec -s -i regedit

(Note: You have to execute this command line from an “administrator” command prompt [right-click command prompt and click run as administrator])

Return to step 3 above

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

When done, you registry entries should look somewhat like the following along with your user id having full permissions to these registry entries:

 

 

 


 

 

 

 

 

 

 

Microsoft Silverlight 2.0 Beta 2 – Setting Initial Focus on Silverlight Control (Textbox)

(The initial discussion was for Silverlight 2.0 Beta 1)

Step #1

Create a dummy textbox for your initial SL XAML and set the following properties as follows:

Opacity="0" IsReadOnly="True" TabIndex="0"

Step #2

In the ‘loaded’ event of your initial SL XAML, paste the following code to the end of that event:

Windows.Browser.HtmlPage.Plugin.Focus()
Dim t As New System.Windows.Threading.DispatcherTimer()
t.Interval = TimeSpan.FromMilliseconds(100)
AddHandler t.Tick, AddressOf t_Tick
t.Start()

Step #3

Add the following Subroutine which includes setting focus on the textbox:

 Private Sub t_Tick(ByVal sender As Object, ByVal e As EventArgs)
    Dim t As System.Windows.Threading.DispatcherTimer = TryCast(sender, System.Windows.Threading.DispatcherTimer)
    t.[Stop]()
    txtUserName.Focus()
End Sub

Warning: Make sure your VB logic does not set focus to any textbox whatsoever prior to the ‘t_Tick’ sub routine setting your textbox of choice first.

Microsoft Silverlight 2.0 Beta 2 – InvalidOperationException occurred

Private WithEvents mylogonService As NewsrLogon.IwcfLogonServiceClient

Error:

Could not find default endpoint element that references contract
‘SilverlightApplication.srLogon.IwcfLogonService’ in the ServiceModel
client configuration section. This might be because no configuration file was
found for your application, or because no endpoint element matching this
contract could be found in the client element.

+++++

According to a Silverlight Forum discussion
(http://silverlight.net/forums/t/18006.aspx) the solution is to fully qualify
the ‘contract’ in the <client/endpoint> section of the
ServiceReferences.ClientConfig file with the Silverlight project name.

<client>
   <endpoint address="http://localhost:59715/wcfLogonService.svc"
   binding="basicHttpBinding"
   bindingConfiguration="BasicHttpBinding_IwcfLogonService"
   contract="SilverlightApplication.srLogon.IwcfLogonService"
   name="BasicHttpBinding_IwcfLogonService"/>
</client>

 

Microsoft Silverlight 2.0 Beta 2 – How to navigate between xaml pages

Add the following to the app.xaml.vb:

 Dim mainUI As Grid = New Grid()

In Private Sub Application_Startup

 Me.RootVisual = mainUI

Add sub:

 Public Sub GoToPage(ByVal nextPg As UserControl)
      Dim app As App = CType(Application.Current, App)
      ' Remove the displayed page
      app.mainUI.Children.Clear()
      ' Show the next page
      app.mainUI.Children.Add(nextPg)
 End Sub

Then in your page:

 Private Sub btnLogon_Click1(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnLogon.Click
      Try
           Dim app As App = CType(Application.Current, App)
           app.GoToPage(New PendListPage())
      Catch ex As Exception
           clsExceptionRoutine.Exception_Routine(ex)
      End Try
 End Sub

Microsoft Silverlight 2.0 Beta 2 – Creating a Custom Splash Screen for aspx page

As noted this is using the html page rather than the aspx page as the startup. Make sure that you are testing with a xap that is large enough to display the splash screen. You can add a large file and set it to Embedded Resource. The xap and splashscreen.xaml have to be in the same folder. Put the following Java Script in the aspx page.

<script type="text/javascript" language="javascript">
Function onSourceDownloadProgressChanged(ByVal sender, ByVal eventArgs)
{
    var p = $get("XAML1?).content; 
    p.findName ( "uxStatus"). Text = "Loading " + Math.round (eventArgs.get_progress () * 100) + "%"; 
    p.findName ( "uxProgressBar"). ScaleY = eventArgs.get_progress () * 356; 
}
<script>
This is an example of the <div used to display the splash screen. Note the items in Red.

<div style="height:100%;">
    <asp:Silverlight ID="Xaml1? runat="server" Source=>"~/SplashScreenSource.xap"
	</span>
    MinimumVersion="2.0.30523? Width="100%" Height="100%" 
    OnPluginError="onSilverlightError" SplashScreenSource="~/SplashScreen.xaml"
	OnPluginSourceDownloadProgressChanged="onSourceDownloadProgressChanged"
</div>

You can use the xaml from the example on the forum to test this. Remember to copy the xap to the same folder as the SplashScreen.xaml. The ~/ means I had it in the same folder as the aspx page. I did find that when you are testing this you have to clear out the browser history/cache to get it to display.

Microsoft Silverlight – Simple Solution for Passing Data from Web Client to Silverlight

Need to find a simple way of passing data from the Web Client portion of your solution to your initial Silverlight control? By using the InitParameters inside the main *.aspx document of the Web Client, you can.

Here is an example piece of vbscript for passing the IpAddress to Silverlight:

 
<script runat="server">
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Try
        Dim strIP As String
        strIP = Request.UserHostAddress.ToString
        Xaml1.InitParameters = "IP=" & strIP.ToString()
    Catch ex As Exception
 
    End Try
End Sub
</script>

In your initial Silverlight control (app.xaml.vb), add the following code to the ‘Application Startup’ subroutine to receive the IpAddress:

 
Private Sub Application_Startup(ByVal o As Object, ByVal e As StartupEventArgs) Handles Me.Startup 
    Dim IPAddress As String
    IPAddress = e.InitParams.Item("IP").ToString
    Me.RootVisual = New host(IPAddress)
End Sub

To continue passing the IPAddress to the next Silverlight control, simply pass add it when creating the new instance of the control. See highlight RED above.

Microsoft Silverlight – Resize controls in a canvas within the web browser

Using the ‘Canvas.RenderTransform’ in your base Silverlight XAML, along with some resizing logic in the base Silverlight .vb class, the controls within your browser will resize as you change the size of the browser.

In this scenario, the App.xaml Application_Startup event passes control to the first displayable Silverlight xaml called, ‘host’, which contains the resizing logic. As long as I don’t remove ‘host’, the resizing logic is not needed in any other xaml.

Example:

In the MyApplication Application, the following flow occurs:

App.xaml executes the following statement that loads the first Silverlight Control:

me.RootVisual = New host(IPAddress)

‘host’ then adds the logon.xaml on top of the ‘host’ with the following statement:

ucLogon = New Logon(mIPAddress)

When the logon is successful, ‘logon’ is removed from host and the main.xaml is then added.

LayoutRoot.Children.Remove(ucLogon)
LayoutRoot.Children.Add(ucMain)

Going forward, all Messages, which are xaml files, are simply added and removed from ‘main’. As long as ‘host’ is never unloaded, resizing the browser will continue to raise the ‘resize’ event logic in the host.xaml.vb class.

How To:

The following markup is needed in the host.xaml.

<UserControl x:Class="SilverlightApplication.host"
xmlns="http://schemas.microsoft.com/client/2007?
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008? xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006? mc:Ignorable="d">
<Canvas x:Name="LayoutRoot" Canvas.Top="0? Canvas.Left="0? Width="800? Height="600?>
<Canvas.Background>
<LinearGradientBrush EndPoint="0.5,1? StartPoint="0.5,0?>
<GradientStop Color="#FF000000?/>
<GradientStop Color="#FF7CA9E7? Offset="1?/>
</LinearGradientBrush>
</Canvas.Background>
<Canvas.RenderTransform>
<TransformGroup>
<ScaleTransform x:Name="RootCanvasScaleTransform" ScaleX="1? ScaleY="1? />
<TranslateTransform x:Name="RootCanvasTranslateTransform" X="0? Y="0? />
</TransformGroup>
</Canvas.RenderTransform>
</Canvas>
</UserControl>

The following code is needed in the host.xaml.vb.

#Region "Private Vars"
    '***RESIZE CONTROLS*** add our event handler
    Private _originalWidth As Double
    Private _originalHeight As Double
    '***RESIZE CONTROLS*** add our event handler
#End Region
 
#Region "Public Events"
    Public Sub New(ByVal pIPAddress As String)
        '***RESIZE CONTROLS*** add our event handler
        Root = Me
        AddHandler Me.Loaded, AddressOf host_Loaded
        '***RESIZE CONTROLS*** add our event handler
    End Sub
#End Region
 
#Region "Public Vars"
    '***RESIZE CONTROLS*** add our event handler
    Public Shared Root As host
    '***RESIZE CONTROLS*** add our event handler
#End Region
 
#Region "Private Event Handlers"
    Private Sub host_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
        Try
            '***RESIZE CONTROLS*** add our event handler
            'Capture the existing height and width.
            _originalWidth = LayoutRoot.Width
            _originalHeight = LayoutRoot.Height
			
            AddHandler Application.Current.Host.Content.Resized, AddressOf Content_Resized
            
			'Define our resize event handler to call Content_Resized method.
            'Call our Resize function for the first time.
            Resize()
            
			'***RESIZE CONTROLS*** add our event handler
            ucLogon = New Logon(mIPAddress)
            LayoutRoot.Children.Add(ucLogon)
        Catch ex As Exception
		
        End Try
    End Sub
 
    '***RESIZE CONTROLS*** add our event handler
    Private Sub Content_Resized(ByVal sender As Object, ByVal e As EventArgs)
        Resize()
    End Sub
 
    '***RESIZE CONTROLS*** add our event handler
    '***RESIZE CONTROLS*** add our event handler
    Private Sub Resize()
        Dim currentWidth As Double = Application.Current.Host.Content.ActualWidth
        Dim currentHeight As Double = Application.Current.Host.Content.ActualHeight
        'We now scale the RootCanvas to fit the control
        Dim uniformScaleAmount As Double = Math.Min((currentWidth / _originalWidth), (currentHeight / _originalHeight))
        RootCanvasScaleTransform.ScaleX = uniformScaleAmount
        RootCanvasScaleTransform.ScaleY = uniformScaleAmount
        Dim scaledWidth As Double = Math.Min(_originalWidth * uniformScaleAmount, currentWidth)
        Dim scaledHeight As Double = Math.Min(_originalHeight * uniformScaleAmount, currentHeight)
        RootCanvasTranslateTransform.X = (Math.Min(LayoutRoot.ActualWidth, currentWidth) – scaledWidth) / 2
        RootCanvasTranslateTransform.Y = (Math.Min(LayoutRoot.ActualHeight, currentHeight) – scaledHeight) / 2 End Sub
        '***RESIZE CONTROLS*** add our event handler
#End Region

Microsoft Silverlight – Hidden Password Textbox

The Textbox in Silverlight currently does not support masking the text when entering for an example a password. This may be supported in the future, but for now a work around was needed. By using a couple event handlers in the the Silverlight control, along with a few public methods in a separate class, it can be done.

The following code needs to be in the Silverlight control that hosts your textbox that needs to be masked.

Public strPassword As String = ""
 
Private Sub txtPassword_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Input.KeyEventArgs) 
    Try
        If e.Key = Key.Enter Then
            btnLogon_Click(sender, e)
            Exit Sub
        End If
 
    Catch ex As Exception
 
    End Try
 
    Try
        Dim mpassword As New HidePassword
        mpassword.ParentObject = Me
        mpassword.hpKeyDown(e)
    Catch ex As Exception
 
    End Try
End Sub
 
Private Sub txtPassword_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.TextChangedEventArgs) 
    Dim mpassword As New HidePassword
    mpassword.ParentObject = Me
    mpassword.hpTextChanged()
End Sub

Create a class called ‘HidePassword’ and populate with the following logic:

 
Public Class HidePassword 
Private mText As String = String.Empty
Private mPasswordChar As Char = "*"
Private mIPAddress As String = ""
Public ParentObject As New Logon(mIPAddress)

Public Sub hpTextChanged()
    If ParentObject.txtPassword.Text.Length >= ParentObject.strPassword.Length Then
       ParentObject.strPassword += ParentObject.txtPassword.Text.Substring(ParentObject.strPassword.Length)
    End If
    
	DisplayMaskedCharacters()
 
End Sub
 
Public Sub hpKeyDown(ByVal e)
    Dim cursorPosition As Integer = ParentObject.txtPassword.SelectionStart
    Dim selectionLength As Integer = ParentObject.txtPassword.SelectionLength
    ' Handle Delete and Backspace Keys Appropriately

    If e.Key = Key.Back Or e.Key = Key.Delete Then
        If cursorPosition < ParentObject.strPassword.Length Then
            Dim lengthToRemove As Integer = 1
            If selectionLength > 0 Then lengthToRemove = selectionLength
            ParentObject.strPassword = ParentObject.strPassword.Remove(cursorPosition, lengthToRemove)
        End If
    End If

    ParentObject.txtPassword.Text = ParentObject.strPassword

    If cursorPosition > ParentObject.strPassword.Length Then
        ParentObject.txtPassword.Select(ParentObject.strPassword.Length, 0)
    Else
        ParentObject.txtPassword.Select(cursorPosition, 0)
    End If
    DisplayMaskedCharacters()
End Sub
 
Private Sub DisplayMaskedCharacters()
    Dim cursorPosition As Integer = ParentObject.txtPassword.SelectionStart
    ' This changes the Text property of the base TextBox class to display all Asterisks in the control
    ParentObject.txtPassword.Text = New String(mPasswordChar, ParentObject.strPassword.Length)

    If cursorPosition > ParentObject.strPassword.Length Then
        ParentObject.txtPassword.Select(ParentObject.strPassword.Length, 0)
    Else
        ParentObject.txtPassword.Select(cursorPosition, 0)
    End If
End Sub

Microsoft Silverlight – Error Logging to Isolated Storage

Isolated storage location is under

C:Users*username*AppDataLocalLowMicrosoftSilverlightis

To handle error logging in Silverlight, create a clsIsolatedStorage.vb

Imports System.IO
Imports System.Xml
Imports System.IO.IsolatedStorage
Imports MyApplication.clsApplicationGlobal
    Public Class clsIsolatedStorage
        Shared Sub ErrorHandler(ByVal mMode As String, ByVal Procedure As String, ByVal e As Exception)
            Try
                WriteToXML(mMode, Procedure, e)
            Catch ex As Exception
                ‘Big Problem
            End Try
        End Sub

        Shared Sub WriteToXML(ByVal mmode As String, ByVal mproc As String, ByVal e As Exception 
            Try
                Using store As IsolatedStorageFile = _
                IsolatedStorageFile.GetUserStoreForApplication()
                    ‘ Create a directory for the files
                    ‘ if it doesn’t already exist. subDirName As String = "SLErrors"
                    If Not store.DirectoryExists(subDirName) Then
                        store.CreateDirectory(subDirName)
                    End If
                End Using

                Dim isoStore As IsolatedStorageFile = _ 
                IsolatedStorageFile.GetUserStoreForApplication()
                ‘ Create/Open file
                Dim isoStream As IsolatedStorageFileStream = _
                New IsolatedStorageFileStream("" & subDirName & "" & "ErrorLog.txt", _
                FileMode.Append, FileAccess.Write, isoStore) "" FileMode.Append, FileAccess.Write
                ‘ Write to the Isolated Storage for the user.

                Using streamWriter As StreamWriter = New StreamWriter(isoStream 
                    Dim settings As XmlWriterSettings = New XmlWriterSettings()
                    settings.Indent = True
                    ‘ Create an XmlWriter.
                    Using writer As XmlWriter = XmlWriter.Create(streamWriter, settings)
                        writer.WriteStartElement("Error")
                        writer.WriteElementString("DateTime", Now)
                        writer.WriteElementString("Module", mmode)
                        writer.WriteElementString("Procedure", mproc)

                        If IsNothing(e) = False Then writer.WriteElementString("ExceptionMessage", e.Message 
                        writer.WriteEndElement()
                        writer.Flush()
                    End Using
                End Using
                isoStream.Close()
                ‘ Open the file again for reading.
                ‘Using reader As New StreamReader(isoStore.OpenFile("SLErrorLog.txt", FileMode.Open))
                ‘ HoldErrors = HoldErrors & reader.ReadToEnd()
                ‘End Using
            Catch ex As Exception
            End Try
        End Sub
    End Class

To use the class:

Private eMod As String = "PageName"
Private eProc As String = ""

Private Sub btnSameAddress_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs 
    eProc = "btnSameAddress_Click"
    Try
        txtAddress.Text = HoldReporterStreet
        txtApartment.Text = HoldReporterApt
        txtCity.Text = HoldReporterCity
        txtState.Text = HoldReporterState
        txtZip.Text = HoldReporterZip
		
    Catch ex As Exception
        clsIsolatedStorage.ErrorHandler(eMod, eProc, ex)
 
    End Try
    txtAddress.Focus()
End Sub

I have a clsApplicationGlobal that holds variables that I use from one page to the next. You may be able to put the public shared in the clsIsolatedStorage as a private variable.

MyApplication_Silverlight_Application.clsApplicationGlobal
 
Public Shared subDirName As String = "SLErrors"

Microsoft Silverlight – Error Handling in Silverlight

If you have an unhandled error sometimes Silverlight will just disappear from IE and leave a blank screen. In the App.xaml.vb under Application_UnhandledException add

e.Handled = True 

SAMPLE:

Private Sub Application_UnhandledException(ByVal sender As Object, ByVal e As ApplicationUnhandledExceptionEventArgs) Handles Me.UnhandledException
    e.Handled = True
End Sub