If a user attempts to install a SLOOB app when it is already installed an InvalidOperationException
is thrown with the message "Application is already installed.". We can wrap in a try..catch to handle this:
try
{
Application.Current.Install();
}
catch (InvalidOperationException ex)
{
MessageBox.Show(ex.Message);
}
Or better yet, remove the install button from the UI if the application is already installed:
if (Application.Current.InstallState == InstallState.Installed)
btnInstall.Visibility = Visibility.Collapsed;
else
btnInstall.Visibility = Visibility.Visible;
SHARE: