Partilhar via


Application.InstallStateChanged Event

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Occurs when the InstallState property value changes.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Event InstallStateChanged As EventHandler
public event EventHandler InstallStateChanged
<Application InstallStateChanged="eventhandler"/>

Examples

The following code example demonstrates how to use this event. This example is part of a larger example available in How to: Implement Offline Support for Out-of-Browser Applications.

Private WithEvents app As Application = Application.Current

Public Sub New()

    InitializeComponent()
    LayoutRoot.DataContext = Deployment.Current.OutOfBrowserSettings
    UpdateUI()

    AddHandler NetworkChange.NetworkAddressChanged, _
        AddressOf UpdateNetworkIndicator

End Sub


...


Private Sub App_InstallStateChanged(ByVal sender As Object, _
    ByVal e As EventArgs) Handles app.InstallStateChanged

    UpdateUI()

End Sub

Private Sub UpdateUI()

    UpdateNetworkIndicator()

    installButton.Visibility = If(
        app.InstallState = InstallState.NotInstalled,
        Visibility.Visible, Visibility.Collapsed)

    updateButton.Visibility = If(app.IsRunningOutOfBrowser,
        Visibility.Visible, Visibility.Collapsed)

    isRunningOutOfBrowserTextBlock.Text = _
        app.IsRunningOutOfBrowser.ToString()

    installStateTextBlock.Text = app.InstallState.ToString()

End Sub

Private Sub UpdateNetworkIndicator()

    If app.IsRunningOutOfBrowser Then
        networkIndicator.Visibility = Visibility.Visible
    Else
        networkIndicator.Visibility = Visibility.Collapsed
    End If



    Dim online As Boolean = NetworkInterface.GetIsNetworkAvailable()


    If online Then
        networkIndicator.Text = "ONLINE" 

        updateButton.Visibility = Visibility.Visible
    Else
        networkIndicator.Text = "OFFLINE"
        updateButton.Visibility = Visibility.Collapsed
    End If

End Sub
Application app = Application.Current;
public MainPage()
{
    InitializeComponent();
    LayoutRoot.DataContext = Deployment.Current.OutOfBrowserSettings;
    UpdateUI();
    app.CheckAndDownloadUpdateCompleted += 
        App_CheckAndDownloadUpdateCompleted;
    app.InstallStateChanged += (s,e) => UpdateUI();
    NetworkChange.NetworkAddressChanged += 
        (s, e) => UpdateNetworkIndicator();

    MessageBox.Show(Deployment.Current.OutOfBrowserSettings
        .WindowSettings.WindowStyle.ToString());
}


...


private void UpdateUI()
{
    UpdateNetworkIndicator();

    installButton.Visibility =
        app.InstallState == InstallState.NotInstalled ?
        Visibility.Visible : Visibility.Collapsed;

    updateButton.Visibility =
        app.IsRunningOutOfBrowser ? 
        Visibility.Visible : Visibility.Collapsed;

    isRunningOutOfBrowserTextBlock.Text = 
        app.IsRunningOutOfBrowser.ToString();

    installStateTextBlock.Text = app.InstallState.ToString();
}

private void UpdateNetworkIndicator()
{
    networkIndicator.Visibility =
        app.IsRunningOutOfBrowser ?
        Visibility.Visible : Visibility.Collapsed;

    bool online = NetworkInterface.GetIsNetworkAvailable();

    networkIndicator.Text = online ?
        "ONLINE" : "OFFLINE";

    updateButton.Visibility = online ?
        Visibility.Visible : Visibility.Collapsed;
}

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.