View/MainWindow.ps1


# 使用する変数を増やしたら、MainWindow.ps1内のRequest-Jobをメンテナンスし忘れない
Function Global:Initialize-MainWindowUI{
    If (!([String]::IsNullOrEmpty($CurrentConfig.Config.AdminName))){
        If (!$CurrentConfig.WizardView.ShowOptionTab){$MainWindow.Dispatcher.Invoke({$MainWindow.FindName("OptionTab").Visibility = [System.Windows.Visibility]::Collapsed})}
        If (!$CurrentConfig.WizardView.ShowServerTab){$MainWindow.Dispatcher.Invoke({$MainWindow.FindName("ServerTab").Visibility = [System.Windows.Visibility]::Collapsed})}
        If (!$CurrentConfig.WizardView.ShowSyncWindowsProductsTab){$MainWindow.Dispatcher.Invoke({$MainWindow.FindName("SyncWindowsProductsTab").Visibility = [System.Windows.Visibility]::Collapsed})}
        If (!$CurrentConfig.WizardView.ShowDeclineRuleTab){$MainWindow.Dispatcher.Invoke({$MainWindow.FindName("DeclineRuleTab").Visibility = [System.Windows.Visibility]::Collapsed})}
        If (!$CurrentConfig.WizardView.ShowApproveRuleOptionsTab){$MainWindow.Dispatcher.Invoke({$MainWindow.FindName("ApproveRuleOptionsTab").Visibility = [System.Windows.Visibility]::Collapsed})}
        If (!$CurrentConfig.WizardView.ShowScheduleTab){$MainWindow.Dispatcher.Invoke({$MainWindow.FindName("ScheduleTab").Visibility = [System.Windows.Visibility]::Collapsed})}
        If (!$CurrentConfig.WizardView.ShowAboutTab){$MainWindow.Dispatcher.Invoke({$MainWindow.FindName("AboutTab").Visibility = [System.Windows.Visibility]::Collapsed})}
    }

    $Global:StatusList = @()
    If (!$CurrentConfig.WizardView.DetectiveInstalledComponents -or !$CurrentConfig.WizardView.ShowOptionTab){
        $MainWindow.FindName("ComponentsListPanel").Visibility = [System.Windows.Visibility]::Collapsed
    }

    $MainWindow.FindName("MainTabControl").Add_SizeChanged({
        $MainWindow.FindName("MainTabControl").OverridesDefaultStyle = $MainWindow.FindName("MainTabControl").ActualWidth -le 800
    })

    $MainWindow.FindName("MainTabControl").Add_SelectionChanged({
        $NavigateTabs = @($MainWindow.FindName("MainTabControl").Items | Where-Object {($_.Visibility -eq [System.Windows.Visibility]::Visible) -and ($_ -ne $MainWindow.FindName("AboutTab"))})
        Switch ($MainWindow.FindName("MainTabControl").SelectedItem){
            $NavigateTabs[0]{
                $MainWindow.FindName("NavigationBarBackButton").Visibility = [System.Windows.Visibility]::Collapsed
                $MainWindow.FindName("NavigationBarFowardButton").Visibility = [System.Windows.Visibility]::Visible
                $MainWindow.FindName("NavigationBarCompleteButton").Visibility = [System.Windows.Visibility]::Collapsed
                $MainWindow.FindName("NavigationBar").Visibility = [System.Windows.Visibility]::Visible
            }
            $NavigateTabs[($NavigateTabs.Count -1)]{
                $MainWindow.FindName("NavigationBarBackButton").Visibility = [System.Windows.Visibility]::Visible
                $MainWindow.FindName("NavigationBarFowardButton").Visibility = [System.Windows.Visibility]::Collapsed
                $MainWindow.FindName("NavigationBarCompleteButton").Visibility = [System.Windows.Visibility]::Visible
                $MainWindow.FindName("NavigationBar").Visibility = [System.Windows.Visibility]::Visible
            }
            $MainWindow.FindName("AboutTab"){
                $MainWindow.FindName("NavigationBar").Visibility = [System.Windows.Visibility]::Collapsed
            }
            Default{
                $MainWindow.FindName("NavigationBarBackButton").Visibility = [System.Windows.Visibility]::Visible
                $MainWindow.FindName("NavigationBarFowardButton").Visibility = [System.Windows.Visibility]::Visible
                $MainWindow.FindName("NavigationBarCompleteButton").Visibility = [System.Windows.Visibility]::Collapsed
                $MainWindow.FindName("NavigationBar").Visibility = [System.Windows.Visibility]::Visible
            }
        }

    })
    $MainWindow.FindName("NavigationBarBackButton").Add_Click({
        $NavigateTabs = @($MainWindow.FindName("MainTabControl").Items | Where-Object {($_.Visibility -eq [System.Windows.Visibility]::Visible) -and ($_ -ne $MainWindow.FindName("AboutTab"))})
        $MainWindow.FindName("MainTabControl").SelectedItem = $NavigateTabs[$NavigateTabs.IndexOf($MainWindow.FindName("MainTabControl").SelectedItem) - 1]
    })
    $MainWindow.FindName("NavigationBarFowardButton").Add_Click({
        $NavigateTabs = @($MainWindow.FindName("MainTabControl").Items | Where-Object {($_.Visibility -eq [System.Windows.Visibility]::Visible) -and ($_ -ne $MainWindow.FindName("AboutTab"))})
        $MainWindow.FindName("MainTabControl").SelectedItem = $NavigateTabs[$NavigateTabs.IndexOf($MainWindow.FindName("MainTabControl").SelectedItem) + 1]
    })
    $MainWindow.FindName("NavigationBarCompleteButton").Add_Click({
        Set-MainWindowSettings
        #$MainWindow.DialogResult = $True
    })

    $Global:DefaultStatusTitle = $MainWindow.FindName("StatusTitle").Text

}

#
# OptionTab
#
Function Global:Initialize-OptionTab{
    $MainWindow.FindName("SqlCmdPathTextBox").DataContext = $CurrentConfig.MaintenanceSql

    $MainWindow.FindName("SqlCmdPathButton").Add_Click({
        $Path = $MainWindow.FindName("SqlCmdPathTextBox").Text
        $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
        $OpenFileDialog.Filter = "SQLCMD.exe|sqlcmd.exe"
        $OpenFileDialog.InitialDirectory = $env:ProgramFiles
        If (![String]::IsNullOrEmpty($Path)){
            If (Test-Path $Path){
                $OpenFileDialog.FileName = $Path
                $OpenFileDialog.InitialDirectory = Split-Path $Path -Parent
            }
        }
        If ($OpenFileDialog.ShowDialog()){
            $MainWindow.FindName("SqlCmdPathTextBox").Text = $OpenFileDialog.FileName
        }
    })

    $MainWindow.FindName("ComponentsListView").Add_DataContextChanged{
        $MainWindow.FindName("ComponentsListView").DataContext | ForEach-Object {
            $_.InstallButton.Add_Click({param($sender)
                $MainWindow.Dispatcher.Invoke({
                    Try{
                        Request-Job -Script {Show-InstallStatusUi} -DependentPs1File (Join-Path $PSScriptRoot "Install-WindowsFeature.Task.ps1") -Arguments $sender | Out-Null
                    }
                    Catch{
                        Write-Warning "[$($Component.DisplayName)] インストールできませんでした: $($_.Exception.Message)"
                        $sender.IsSelected = $False
                    }
                })
            })
        }
    }

}

#
# ServerTab
#
Function Global:Initialize-ServerTab{
    $MainWindow.FindName("WsusServerTextBox").DataContext = $CurrentConfig.Wsus
    $MainWindow.FindName("WsusServerPortTextBox").Text = $CurrentConfig.Wsus.Port
    $MainWindow.FindName("WsusServerUseSslCheckBox").DataContext = $CurrentConfig.Wsus
    $MainWindow.FindName("IisWsusPoolTextBox").DataContext = $CurrentConfig.Wsus
    $MainWindow.FindName("ServerInstancePathTextBox").DataContext = $CurrentConfig.MaintenanceSql

    $MainWindow.FindName("TestConnectionWsusServerButton").Add_Click({
        $MainWindow.FindName("WsusServerTextBox").Focus()
        $MainWindow.FindName("TestConnectionWsusServerButton").IsEnabled = $False
        Initialize-TestResultMessages
        
        Request-Job -Script {Test-ServerAllFunctions} -DependentPs1File (Join-Path $PSScriptRoot "Test-ServerAllFunctions.Task.ps1") | Out-Null
    })

    $MainWindow.FindName("WsusServerTextBox").Add_TextChanged({
        Initialize-TestResultMessages
        $MainWindow.FindName("TestConnectionWsusServerButton").IsEnabled = $True
    })
    $MainWindow.FindName("WsusServerPortTextBox").Add_TextChanged({
        Initialize-TestResultMessages
        $MainWindow.FindName("TestConnectionWsusServerButton").IsEnabled = $True
        $CurrentConfig.Wsus.Port = $MainWindow.FindName("WsusServerPortTextBox").Text
    })
    $MainWindow.FindName("WsusServerUseSslCheckBox").Add_Checked({
        If ($MainWindow.FindName("WsusServerPortTextBox").Text -eq 8530){
            $MainWindow.FindName("WsusServerPortTextBox").Text = 8531
        }
    })
    $MainWindow.FindName("WsusServerUseSslCheckBox").Add_UnChecked({
        If ($MainWindow.FindName("WsusServerPortTextBox").Text -eq 8531){
            $MainWindow.FindName("WsusServerPortTextBox").Text = 8530
        }
    })
}
Function Global:Initialize-TestResultMessages{
    $MainWindow.FindName("AllConnectionSuccessfully").Visibility = [System.Windows.Visibility]::Collapsed
    $MainWindow.FindName("WsusServerConnectionFailure").Visibility = [System.Windows.Visibility]::Collapsed
    $MainWindow.FindName("WsusPoolApplicationContainer").Visibility = [System.Windows.Visibility]::Collapsed
    $MainWindow.FindName("SqlConnectionFailure").Visibility = [System.Windows.Visibility]::Collapsed
    $MainWindow.FindName("IisConnectionFailure").Visibility = [System.Windows.Visibility]::Collapsed
}

#
# ServerConfigTab
#
Function Global:Initialize-ServerConfigTab{
    $MainWindow.FindName("WsusServerPortTextBox").Text = $CurrentConfig.Wsus.Port
    
    If (Get-FsResourceManagerInstalledStatus){
        $MainWindow.FindName("FileQuotaContainer").Visibility = [System.Windows.Visibility]::Visible
        
        $WsusContentDirectory = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Update Services\Server\Setup").ContentDir
        If ($WsusContentDirectory -ne $Null){
            If (Test-Path $WsusContentDirectory){
                $MainWindow.FindName("ConfigureFileQuataCheckBox").IsEnabled = $True
                $MainWindow.FindName("QuotaSizeTextBox").Enabled = $True

                $MainWindow.FindName("WsusContentFolderInformationListBoxItem").DataContext = ([String]::Format("現在 {0}", ((Get-ChildItem $WsusContentDirectory -Recurse | Measure-Object -Property Length -Sum).Sum | Convert-DisplayByteSize)))
                $VolumeInformation = Get-Volume -FilePath $WsusContentDirectory
                $MainWindow.FindName("WsusContentDriveInformationListBoxItem").DataContext = ([String]::Format("空き領域 {0} / {1}", ($VolumeInformation.SizeRemaining | Convert-DisplayByteSize), ($VolumeInformation.Size | Convert-DisplayByteSize)))

                $MainWindow.FindName("QuotaSizeTextBox").Maximum = [int]($VolumeInformation.Size / 1073741824)
            }
        }
    }
    
}

#
# SyncWindowsProductsTab
#
Function Global:Initialize-SyncWindowsProductsTab{
    Function Script:Get-WindowsProductLifecycleItem($Source, [WindowsVersion]$Parent){
        Enum WindowsVersion{
            Windows10
            Windows11
        }
        $Item = (New-Object -TypeName WindowsProductLifecycleItem)
        $Item.Add_SelectionChanged({param($sender, $e)
            Sync-WindowsProductLifecycleItem -sender $sender -e $e
        })

        $Item.Title = $Source.Title
        $Item.Version = $Source.Version
        $Item.EndDate = $Source.EndDate
        $Item.NeededProducts = $Source.NeededProducts
        $Item.IsPro = $Source.IsPro
        $Item.IsEnterpriseWithoutLtsc = $Source.IsEnterpriseWithoutLtsc
        $Item.IsLtsc = $Source.IsLtsc
        $Item.VisibleX86 = $Source.VisibleX86
        $Item.VisibleX64 = $Source.VisibleX64
        $Item.VisibleArm64 = $Source.VisibleArm64

        If ($Source.IsPro -like "true"){$Item.IsPro = $True}Else{$Item.IsPro = $False}
        If ($Source.IsEnterpriseWithoutLtsc -like "true"){$Item.IsEnterpriseWithoutLtsc = $True}Else{$Item.IsEnterpriseWithoutLtsc = $False}
        If ($Source.IsLtsc -like "true"){$Item.IsLtsc = $True}Else{$Item.IsLtsc = $False}
        If ($Source.VisibleX86 -like "true"){$Item.VisibleX86 = $True}Else{$Item.VisibleX86 = $False}
        If ($Source.VisibleX64 -like "true"){$Item.VisibleX64 = $True}Else{$Item.VisibleX64 = $False}
        If ($Source.VisibleArm64 -like "true"){$Item.VisibleArm64 = $True}Else{$Item.VisibleArm64 = $False}

        $Item | Add-Member -MemberType NoteProperty -Name Parent -Value $Parent

        Return $Item
    }
    Function Script:Invoke-SynWindowsShowLtscOnlyToggleButtonChecked($sender, $e){
        If ($IgnoreSynWindowsShowLtscOnlyToggleButtonCheckEvent){
            Return
        }
        $MainWindow.FindName("SynWindowsShowLtscOnlyToggleButton").IsEnabled = $False
        $MessageText = "LTSCのみの選択に切り替えると、この画面で行った選択が解除されます。"
        If ([System.Windows.Forms.MessageBox]::Show("$MessageText`n続行してもよろしいですか?","", [System.Windows.Forms.MessageBoxButtons]::YesNo , [System.Windows.Forms.MessageBoxIcon]::Question) -ne [System.Windows.Forms.DialogResult]::Yes){
            $Script:IgnoreSynWindowsShowLtscOnlyToggleButtonCheckEvent = $True
            $LastCheckedSynWindowsCheckBox.IsChecked = $True
            $MainWindow.FindName("SynWindowsShowLtscOnlyToggleButton").IsEnabled = $True
            $Script:IgnoreSynWindowsShowLtscOnlyToggleButtonCheckEvent = $False
        }
        Else{
            $LastCheckedSynWindowsCheckBox.Focus()
            Get-WindowsProductsItems
            Set-WindowsProductsFiltersCheckBox
        }
    }
    Function Script:Invoke-SynWindowsShowLtscOnlyToggleButtonUnChecked($sender, $e){
        If ($IgnoreSynWindowsShowLtscOnlyToggleButtonCheckEvent){
            Return
        }
        $MessageText = "Pro・Enterprise・Educationの選択に切り替えると、この画面で行った選択が解除されます。"
        If ([System.Windows.Forms.MessageBox]::Show("$MessageText`n続行してもよろしいですか?","", [System.Windows.Forms.MessageBoxButtons]::YesNo , [System.Windows.Forms.MessageBoxIcon]::Question) -ne [System.Windows.Forms.DialogResult]::Yes){
            $Script:IgnoreSynWindowsShowLtscOnlyToggleButtonCheckEvent = $True
            $MainWindow.FindName("SynWindowsShowLtscOnlyToggleButton").IsChecked = $True
            $Script:IgnoreSynWindowsShowLtscOnlyToggleButtonCheckEvent = $False
        }
        Else{
            Get-WindowsProductsItems
            Set-WindowsProductsFiltersCheckBox
        }
    }
    Function Script:Set-WindowsProductsFiltersCheckBox{
        $FilteredWindows10Products = $Windows10Products | Sort-Object Version -Descending
        $FilteredWindows11Products = $Windows11Products | Sort-Object Version -Descending

        If (-not $MainWindow.FindName("SynWindowsShowEndOfSupportProductsCheckBox").IsChecked){
            $FilteredWindows10Products = $FilteredWindows10Products | Where-Object {(Get-Date) -le $_.EndDate}
            $FilteredWindows11Products = $FilteredWindows11Products | Where-Object {(Get-Date) -le $_.EndDate}
            $MainWindow.FindName("SyncWindowsProductsWindows81ListBoxItem").Visibility = [System.Windows.Visibility]::Visible
        }
        If ($MainWindow.FindName("SynWindowsShowEnterpriseWithoutLtscOnlyRadioButton").IsChecked){
            $FilteredWindows10Products = $FilteredWindows10Products | Where-Object IsEnterpriseWithoutLtsc
            $FilteredWindows11Products = $FilteredWindows11Products | Where-Object IsEnterpriseWithoutLtsc
            $MainWindow.FindName("SyncWindowsProductsWindows81ListBoxItem").Visibility = [System.Windows.Visibility]::Visible
            $MainWindow.FindName("SynWindowsShowLtscOnlyToggleButton").IsEnabled = $True
        }
        ElseIf ($MainWindow.FindName("SynWindowsShowLtscOnlyToggleButton").IsChecked){
            $FilteredWindows10Products = $FilteredWindows10Products | Where-Object IsLtsc
            $FilteredWindows11Products = $FilteredWindows11Products | Where-Object IsLtsc
            $MainWindow.FindName("SyncWindowsProductsWindows81ListBoxItem").Visibility = [System.Windows.Visibility]::Collapsed
        }
        Else{
            $FilteredWindows10Products = $FilteredWindows10Products | Where-Object IsPro
            $FilteredWindows11Products = $FilteredWindows11Products | Where-Object IsPro
            $MainWindow.FindName("SynWindowsShowLtscOnlyToggleButton").IsEnabled = $True
        }

        If ($MainWindow.FindName("SynWindowsShowArchitectureCheckBox").IsChecked){
            $MainWindow.FindName("SyncWindowsProductsWindows11Lists").ItemTemplate = $MainWindow.FindResource("SyncWindowFeatureUpdateArchitectureChooser")
            $MainWindow.FindName("SyncWindowsProductsWindows10Lists").ItemTemplate = $MainWindow.FindResource("SyncWindowFeatureUpdateArchitectureChooser")

            $MainWindow.FindName("SynWindowsChooseWindows81CheckBox").Visibility = [System.Windows.Visibility]::Collapsed
            $MainWindow.FindName("SynWindowsChooseWindows81x64CheckBox").Visibility = [System.Windows.Visibility]::Visible
            $MainWindow.FindName("SynWindowsChooseWindows81x86CheckBox").Visibility = [System.Windows.Visibility]::Visible
            
            $MainWindow.FindName("SynWindowsChooseMsEdgeCheckBox").Visibility = [System.Windows.Visibility]::Collapsed
            $MainWindow.FindName("SynWindowsChooseMsEdgeX64CheckBox").Visibility = [System.Windows.Visibility]::Visible
            $MainWindow.FindName("SynWindowsChooseMsEdgeX86CheckBox").Visibility = [System.Windows.Visibility]::Visible
            $MainWindow.FindName("SynWindowsChooseMsEdgeArm64CheckBox").Visibility = [System.Windows.Visibility]::Visible
        }
        Else{
            $MainWindow.FindName("SyncWindowsProductsWindows11Lists").ItemTemplate = $MainWindow.FindResource("SyncWindowFeatureUpdateChooser")
            $MainWindow.FindName("SyncWindowsProductsWindows10Lists").ItemTemplate = $MainWindow.FindResource("SyncWindowFeatureUpdateChooser")
            
            $MainWindow.FindName("SynWindowsChooseWindows81CheckBox").Visibility = [System.Windows.Visibility]::Visible
            $MainWindow.FindName("SynWindowsChooseWindows81x64CheckBox").Visibility = [System.Windows.Visibility]::Collapsed
            $MainWindow.FindName("SynWindowsChooseWindows81x86CheckBox").Visibility = [System.Windows.Visibility]::Collapsed
            
            $MainWindow.FindName("SynWindowsChooseMsEdgeCheckBox").Visibility = [System.Windows.Visibility]::Visible
            $MainWindow.FindName("SynWindowsChooseMsEdgeX64CheckBox").Visibility = [System.Windows.Visibility]::Collapsed
            $MainWindow.FindName("SynWindowsChooseMsEdgeX86CheckBox").Visibility = [System.Windows.Visibility]::Collapsed
            $MainWindow.FindName("SynWindowsChooseMsEdgeArm64CheckBox").Visibility = [System.Windows.Visibility]::Collapsed
        }

        If ($FilteredWindows10Products.Count -eq 0){
            $MainWindow.FindName("SyncWindowsProductsWindows10Expander").Visibility = [System.Windows.Visibility]::Collapsed
        }
        Else{
            $MainWindow.FindName("SyncWindowsProductsWindows10Expander").Visibility = [System.Windows.Visibility]::Visible
        }
        If ($FilteredWindows11Products.Count -eq 0){
            $MainWindow.FindName("SyncWindowsProductsWindows11Expander").Visibility = [System.Windows.Visibility]::Collapsed
        }
        Else{
            $MainWindow.FindName("SyncWindowsProductsWindows11Expander").Visibility = [System.Windows.Visibility]::Visible
        }

        $Windows10ProductsCollection = New-Object -TypeName "System.Collections.ObjectModel.ObservableCollection``1[[WindowsProductLifecycleItem]]"
        $FilteredWindows10Products | ForEach-Object{$Windows10ProductsCollection.Add($_)}
        $MainWindow.FindName("SyncWindowsProductsWindows10Lists").DataContext = $Windows10ProductsCollection
        $Windows11ProductsCollection = New-Object -TypeName "System.Collections.ObjectModel.ObservableCollection``1[[WindowsProductLifecycleItem]]"
        $FilteredWindows11Products | ForEach-Object{$Windows11ProductsCollection.Add($_)}
        $MainWindow.FindName("SyncWindowsProductsWindows11Lists").DataContext = $Windows11ProductsCollection
    }
    Function Script:Get-WindowsProductsItems{
        If (Test-Path (Join-Path $PSScriptRoot "..\Assets\Lifecycle--Windows 10.csv")){
            $Global:Windows10Products = (Import-Csv (Join-Path $PSScriptRoot "..\Assets\Lifecycle--Windows 10.csv") -Encoding UTF8) | ForEach-Object {(Get-WindowsProductLifecycleItem -Source $_ -Parent Windows10)}
        }Else{
            $MainWindow.FindName("SyncWindowsProductsWindows10Expander").IsEnabled = $False
        }
        If (Test-Path (Join-Path $PSScriptRoot "..\Assets\Lifecycle--Windows 11.csv")){
            $Global:Windows11Products = (Import-Csv (Join-Path $PSScriptRoot "..\Assets\Lifecycle--Windows 11.csv") -Encoding UTF8) | ForEach-Object {(Get-WindowsProductLifecycleItem -Source $_ -Parent Windows11)}
        }Else{
            $MainWindow.FindName("SyncWindowsProductsWindows11Expander").IsEnabled = $False
        }
    }
    Function Script:Set-Windows81FiltersCheckBox{
        If ($IgnoreWindows81FiltersCheckBoxCheckEvent){
            Return
        }
        $Script:IgnoreWindows81FiltersCheckBoxCheckEvent = $True
        $MainWindow.FindName("SynWindowsChooseWindows81x64CheckBox").IsChecked = $MainWindow.FindName("SynWindowsChooseWindows81CheckBox").IsChecked
        $MainWindow.FindName("SynWindowsChooseWindows81x86CheckBox").IsChecked = $MainWindow.FindName("SynWindowsChooseWindows81CheckBox").IsChecked
        $Script:IgnoreWindows81FiltersCheckBoxCheckEvent = $False
    }
    Function Script:Set-Windows81ArchitectureFiltersCheckBox{
        If ($IgnoreWindows81FiltersCheckBoxCheckEvent){
            Return
        }
        $Script:IgnoreWindows81FiltersCheckBoxCheckEvent = $True
        If ($MainWindow.FindName("SynWindowsChooseWindows81x64CheckBox").IsChecked -and $MainWindow.FindName("SynWindowsChooseWindows81x86CheckBox").IsChecked){
            $MainWindow.FindName("SynWindowsChooseWindows81CheckBox").IsChecked = $True
        }
        ElseIf (-not $MainWindow.FindName("SynWindowsChooseWindows81x64CheckBox").IsChecked -and -not $MainWindow.FindName("SynWindowsChooseWindows81x86CheckBox").IsChecked){
            $MainWindow.FindName("SynWindowsChooseWindows81CheckBox").IsChecked = $False
        }
        Else {
            $MainWindow.FindName("SynWindowsChooseWindows81CheckBox").IsChecked = $Null
        }
        $Script:IgnoreWindows81FiltersCheckBoxCheckEvent = $False
    }
    Function Script:Set-MsEdgeFiltersCheckBox{
        If ($IgnorMsEdgeFiltersCheckBoxCheckEvent){
            Return
        }
        $Script:IgnorMsEdgeFiltersCheckBoxCheckEvent = $True
        $MainWindow.FindName("SynWindowsChooseMsEdgeX64CheckBox").IsChecked = $MainWindow.FindName("SynWindowsChooseMsEdgeCheckBox").IsChecked
        $MainWindow.FindName("SynWindowsChooseMsEdgeX86CheckBox").IsChecked = $MainWindow.FindName("SynWindowsChooseMsEdgeCheckBox").IsChecked
        $MainWindow.FindName("SynWindowsChooseMsEdgeArm64CheckBox").IsChecked = $MainWindow.FindName("SynWindowsChooseMsEdgeCheckBox").IsChecked
        $Script:IgnorMsEdgeFiltersCheckBoxCheckEvent = $False
    }
    Function Script:Set-MsEdgeArchitectureFiltersCheckBox{
        If ($IgnorMsEdgeFiltersCheckBoxCheckEvent){
            Return
        }
        $Script:IgnorMsEdgeFiltersCheckBoxCheckEvent = $True
        If ($MainWindow.FindName("SynWindowsChooseMsEdgeX64CheckBox").IsChecked -and $MainWindow.FindName("SynWindowsChooseMsEdgeX86CheckBox").IsChecked -and $MainWindow.FindName("SynWindowsChooseMsEdgeArm64CheckBox").IsChecked){
            $MainWindow.FindName("SynWindowsChooseMsEdgeCheckBox").IsChecked = $True
        }
        ElseIf (-not $MainWindow.FindName("SynWindowsChooseMsEdgeX64CheckBox").IsChecked -and -not $MainWindow.FindName("SynWindowsChooseMsEdgeX86CheckBox").IsChecked -and -not $MainWindow.FindName("SynWindowsChooseMsEdgeArm64CheckBox").IsChecked){
            $MainWindow.FindName("SynWindowsChooseMsEdgeCheckBox").IsChecked = $False
        }
        Else {
            $MainWindow.FindName("SynWindowsChooseMsEdgeCheckBox").IsChecked = $Null
        }
        $Script:IgnorMsEdgeFiltersCheckBoxCheckEvent = $False
    }

    $Script:IgnoreSynWindowsShowLtscOnlyToggleButtonCheckEvent = $False
    Get-WindowsProductsItems
    Set-WindowsProductsFiltersCheckBox
    $MainWindow.FindName("SynWindowsShowEndOfSupportProductsCheckBox").Add_Checked({Set-WindowsProductsFiltersCheckBox})
    $MainWindow.FindName("SynWindowsShowEndOfSupportProductsCheckBox").Add_UnChecked({Set-WindowsProductsFiltersCheckBox})
    $MainWindow.FindName("SynWindowsShowProOnlyRadioButton").Add_Checked({param($sender, $e)$Global:LastCheckedSynWindowsCheckBox = $sender;Set-WindowsProductsFiltersCheckBox})
    $MainWindow.FindName("SynWindowsShowEnterpriseWithoutLtscOnlyRadioButton").Add_Checked({param($sender, $e)$Global:LastCheckedSynWindowsCheckBox = $sender;Set-WindowsProductsFiltersCheckBox})
    $MainWindow.FindName("SynWindowsShowLtscOnlyToggleButton").Add_Checked({param($sender, $e)Invoke-SynWindowsShowLtscOnlyToggleButtonChecked -sender $sender -e $e})
    $MainWindow.FindName("SynWindowsShowLtscOnlyToggleButton").Add_UnChecked({param($sender, $e)Invoke-SynWindowsShowLtscOnlyToggleButtonUnChecked -sender $sender -e $e})
    $MainWindow.FindName("SynWindowsShowArchitectureCheckBox").Add_Checked({Set-WindowsProductsFiltersCheckBox})
    $MainWindow.FindName("SynWindowsShowArchitectureCheckBox").Add_UnChecked({Set-WindowsProductsFiltersCheckBox})

    $MainWindow.FindName("SynWindowsChooseWindows81CheckBox").Add_Checked({Set-Windows81FiltersCheckBox})
    $MainWindow.FindName("SynWindowsChooseWindows81CheckBox").Add_UnChecked({Set-Windows81FiltersCheckBox})
    $MainWindow.FindName("SynWindowsChooseWindows81x64CheckBox").Add_Checked({Set-Windows81ArchitectureFiltersCheckBox})
    $MainWindow.FindName("SynWindowsChooseWindows81x64CheckBox").Add_UnChecked({Set-Windows81ArchitectureFiltersCheckBox})
    $MainWindow.FindName("SynWindowsChooseWindows81x86CheckBox").Add_Checked({Set-Windows81ArchitectureFiltersCheckBox})
    $MainWindow.FindName("SynWindowsChooseWindows81x86CheckBox").Add_UnChecked({Set-Windows81ArchitectureFiltersCheckBox})

    $MainWindow.FindName("SynWindowsChooseMsEdgeCheckBox").Add_Checked({Set-MsEdgeFiltersCheckBox})
    $MainWindow.FindName("SynWindowsChooseMsEdgeCheckBox").Add_UnChecked({Set-MsEdgeFiltersCheckBox})
    $MainWindow.FindName("SynWindowsChooseMsEdgeX64CheckBox").Add_Checked({Set-MsEdgeArchitectureFiltersCheckBox})
    $MainWindow.FindName("SynWindowsChooseMsEdgeX64CheckBox").Add_UnChecked({Set-MsEdgeArchitectureFiltersCheckBox})
    $MainWindow.FindName("SynWindowsChooseMsEdgeX86CheckBox").Add_Checked({Set-MsEdgeArchitectureFiltersCheckBox})
    $MainWindow.FindName("SynWindowsChooseMsEdgeX86CheckBox").Add_UnChecked({Set-MsEdgeArchitectureFiltersCheckBox})
    $MainWindow.FindName("SynWindowsChooseMsEdgeArm64CheckBox").Add_Checked({Set-MsEdgeArchitectureFiltersCheckBox})
    $MainWindow.FindName("SynWindowsChooseMsEdgeArm64CheckBox").Add_UnChecked({Set-MsEdgeArchitectureFiltersCheckBox})

    $MainWindow.FindName("SynWindowsShowProOnlyRadioButton").IsChecked = $True
    $Global:LastCheckedSynWindowsCheckBox = $MainWindow.FindName("SynWindowsShowProOnlyRadioButton")

    $MainWindow.FindName("SynWindowsChooseWindows81x64CheckBox").DataContext = $CurrentConfig.ChooseProducts."Windows 8.1"
    $MainWindow.FindName("SynWindowsChooseWindows81x86CheckBox").DataContext = $CurrentConfig.ChooseProducts."Windows 8.1"
    $MainWindow.FindName("SynWindowsChooseMsEdgeX64CheckBox").DataContext = $CurrentConfig.ChooseProducts."Microsoft Edge"
    $MainWindow.FindName("SynWindowsChooseMsEdgeX86CheckBox").DataContext = $CurrentConfig.ChooseProducts."Microsoft Edge"
    $MainWindow.FindName("SynWindowsChooseMsEdgeX86CheckBox").DataContext = $CurrentConfig.ChooseProducts."Microsoft Edge"
}

function Global:Sync-WindowsProductLifecycleItem($sender, $e){
    Function Compare-SelectedFlag($Selected, $Visible){
        If (-not $Visible){
            Return $True
        }
        Return $Selected
    }   
    # 編集中の項目はキャンセル
    If ($sender.SelectionChangedCancelRequest){
        Return
    }

    Switch ($sender.Parent){
        Windows10{
            $CurrentProducts = $Windows10Products
        }
        Windows11{
            $CurrentProducts = $Windows11Products
        }
    }

    # チェックされた項目を確認
    $EnabledName = $e.Trigger -replace "Selected", "Enabled"

    # バージョンが同一の項目を同期にする
    $CurrentProducts | Where-Object {($_.Version -eq $sender.Version) -and ($_.Title -ne $sender.Title) -and ($_.Selected -ne $sender.$($e.Trigger))} | ForEach-Object {
        $_.SelectionChangedCancelRequest = $True
        $_.$($e.Trigger) = $sender.$($e.Trigger)
        $_.$($EnabledName) = $True

        $_.SelectionChangedCancelRequest = $False
    }

    # 選択したバージョン前後の項目の選択状態を修正する
    $CurrentProducts | ForEach-Object{
        $_.SelectionChangedCancelRequest = $True
        If ($_.Version -gt $sender.Version){
            # LTSCバージョンの選択は自由にする
            If (-not $_.IsLtsc){
                $_.$($EnabledName) = $False
                If ($e.Trigger -eq [WindowsProductLifecycleItem+SelectionChangedEventArgs+Reason]::Selected){
                    $_.EnabledX86 = $False
                    $_.EnabledX64 = $False
                    $_.EnabledArm64 = $False
                }
                Else{
                    $_.Enabled = $False
                }
            }
            $_.$($e.Trigger) = $True
        }
        ElseIf ($_.Version -lt $sender.Version){
            $_.$($EnabledName) = $True
            $_.$($e.Trigger) = $False
        }
        
        $_.SelectionChangedCancelRequest = $False
    }

    # 選択が外れたとき、選択したバージョンの次のバージョンを有効状態にする
    $CurrentProducts | Select-Object Version | Where-Object Version -gt $sender.Version | Get-Unique | Select-Object -First 1 | ForEach-Object {
        If (-not $sender.$($e.Trigger)){
            $NextVersion = $_.Version
            $CurrentProducts | Where-Object {$_.Version -eq $NextVersion} | ForEach-Object {
                $_.$($EnabledName) = $True
            }
        }
    }

    If ($e.Trigger -eq [WindowsProductLifecycleItem+SelectionChangedEventArgs+Reason]::Selected){
        $CurrentProducts | ForEach-Object {
            $_.SelectionChangedCancelRequest = $True
            $_.SelectedX86 = $_.Selected
            $_.SelectedX64 = $_.Selected
            $_.SelectedArm64 = $_.Selected
            $_.EnabledX86 = $_.Enabled
            $_.EnabledX64 = $_.Enabled
            $_.EnabledArm64 = $_.Enabled
            $_.SelectionChangedCancelRequest = $False
        }
    }
    Else{
        $CurrentProducts | ForEach-Object {
            If ((Compare-SelectedFlag $_.SelectedX86 $_.VisibleX86) -and (Compare-SelectedFlag $_.SelectedX64 $_.VisibleX64) -and (Compare-SelectedFlag $_.SelectedArm64 $_.VisibleArm64)){
                $_.SelectionChangedCancelRequest = $True
                $_.Selected = $True
                $_.SelectionChangedCancelRequest = $False
            }
            ElseIf (-not (Compare-SelectedFlag $_.SelectedX86 $_.VisibleX86) -and -not (Compare-SelectedFlag $_.SelectedX64 $_.VisibleX64) -and -not (Compare-SelectedFlag $_.SelectedArm64 $_.VisibleArm64)){
                $_.SelectionChangedCancelRequest = $True
                $_.Selected = $False
                $_.SelectionChangedCancelRequest = $False
            }
            Else{
                $_.SelectionChangedCancelRequest = $True
                $_.Selected = $Null
                $_.SelectionChangedCancelRequest = $False
            }
        }
    }

    $sender.$($EnabledName) = $True
}

#
# DeclineRuleTab
#
Function Global:Initialize-DeclineRuleTab{
    $MainWindow.FindName("FeatureOnDemandDocumentsHyperlink").Add_Click({param($sender,$e)
        Try{
            Start-Process $sender.NavigateUri
        }
        Catch{}
    })
    $MainWindow.FindName("DynamicUpdateDocumentsHyperlink").Add_Click({param($sender,$e)
        Try{
            Start-Process $sender.NavigateUri
        }
        Catch{}
    })

    # 全般
    $MainWindow.FindName("UseWsusCleanupWizardWithCompressUpdateCheckBox").DataContext = $CurrentConfig.DeclineOptions.CleanupWizard
    $MainWindow.FindName("UseWsusCleanupWizardWithCompressUpdateCheckBox").Add_Checked{$CurrentConfig.DeclineOptions.CleanupWizard.CleanupObsoleteUpdates = $True}
    $MainWindow.FindName("UseWsusCleanupWizardWithCompressUpdateCheckBox").Add_UnChecked{$CurrentConfig.DeclineOptions.CleanupWizard.CleanupObsoleteUpdates = $False}
    $MainWindow.FindName("UseWsusCleanupWizardOthersCheckBox").DataContext = $CurrentConfig.DeclineOptions.CleanupWizard
    $MainWindow.FindName("UseWsusCleanupWizardOthersCheckBox").Add_Checked{
        $CurrentConfig.DeclineOptions.CleanupWizard.DeclineExpiredUpdates = $True
        $CurrentConfig.DeclineOptions.CleanupWizard.DeclineSupersededUpdates = $True
    }
    $MainWindow.FindName("UseWsusCleanupWizardOthersCheckBox").Add_UnChecked{
        $CurrentConfig.DeclineOptions.CleanupWizard.DeclineExpiredUpdates = $False
        $CurrentConfig.DeclineOptions.CleanupWizard.DeclineSupersededUpdates = $False
    }
    $MainWindow.FindName("ForceDeclineSuperseedsUpdatesCheckBox").DataContext = $CurrentConfig.DeclineOptions.CleanupWizard

    # Office
    $MainWindow.FindName("DeclineRuleOfficeX64CheckBox").DataContext = $CurrentConfig.DeclineOptions.Office
    $MainWindow.FindName("DeclineRuleOfficeX86CheckBox").DataContext = $CurrentConfig.DeclineOptions.Office

    # Microsoft Edge (Chromium)
    $MainWindow.FindName("DeclineRuleMsEdgeBetaCheckBox").DataContext = $CurrentConfig.DeclineOptions."Microsoft Edge"
    $MainWindow.FindName("DeclineRuleMsEdgeDevCheckBox").DataContext = $CurrentConfig.DeclineOptions."Microsoft Edge"
    $MainWindow.FindName("DeclineRuleMsEdgeStableCheckBox").DataContext = $CurrentConfig.DeclineOptions."Microsoft Edge"
    $MainWindow.FindName("DeclineRuleMsEdgeExtendStableCheckBox").DataContext = $CurrentConfig.DeclineOptions."Microsoft Edge"
    $MainWindow.FindName("DeclineRuleMsEdgeWebView2RuntimeCheckBox").DataContext = $CurrentConfig.DeclineOptions."Microsoft Edge"
    $MainWindow.FindName("DeclineMsEdgeOldVersionsCheckBox").DataContext = $CurrentConfig.DeclineOptions."Microsoft Edge"

    # システムの種類
    $MainWindow.FindName("DeclineRuleX64CheckBox").DataContext = $CurrentConfig.DeclineOptions.SystemType
    $MainWindow.FindName("DeclineRuleX86CheckBox").DataContext = $CurrentConfig.DeclineOptions.SystemType
    $MainWindow.FindName("DeclineRuleArm64CheckBox").DataContext = $CurrentConfig.DeclineOptions.SystemType

    # 機能更新プログラム
    $MainWindow.FindName("DeclineRuleBusinessCheckBox").DataContext = $CurrentConfig.DeclineOptions.FeatureUpdate
    $MainWindow.FindName("DeclineRuleConsumerCheckBox").DataContext = $CurrentConfig.DeclineOptions.FeatureUpdate

    # その他
    $MainWindow.FindName("IgnoreWindows10Version1809AndEarlierCheckBox").DataContext = $CurrentConfig.DeclineOptions
    $MainWindow.FindName("DeclineDynamicUpdateCheckBox").DataContext = $CurrentConfig.DeclineOptions
    $MainWindow.FindName("DeclineFeatureOnDemandCheckBox").DataContext = $CurrentConfig.DeclineOptions
    $MainWindow.FindName("DeclineRuleLanguagePackCheckBox").DataContext = $CurrentConfig.DeclineOptions
    $MainWindow.FindName("DeclineRuleWindowsServerCheckBox").DataContext = $CurrentConfig.DeclineOptions
    $MainWindow.FindName("DeclineRuleInsiderPreviewCheckBox").DataContext = $CurrentConfig.DeclineOptions
}

#
# ApproveRuleOptionsTab
#
Function Global:Initialize-ApproveRuleOptionsTab{
    $Global:ApproveNeededUpdatesRule = New-Object -TypeName "System.Collections.ObjectModel.ObservableCollection``1[[ApproveNeededUpdatesRuleItem]]"
    $MainWindow.FindName("ApproveRuleList").DataContext = $Global:ApproveNeededUpdatesRule

    $MainWindow.FindName("ApproveRuleAddButton").Add_Click({
        $Item = (New-Object -TypeName ApproveNeededUpdatesRuleItem)

        $Item.RemoveItemButton_Click.Add_Click({
            $Global:ApproveNeededUpdatesRule.Remove($MainWindow.FindName("ApproveRuleList").SelectedItem)
        })
        $Global:ApproveNeededUpdatesRule.Add($Item)
    })
}

#
# ScheduleTab
#
Function Global:Initialize-ScheduleTab{
    $MainWindow.FindName("ScheduleTabDescription").Tag = ($MainWindow.FindName("ScheduleTabDescription").Tag -f $CurrentConfig.ScheduledTask.Name)

    Set-ScheduleTriggersCheckBox
    $MainWindow.FindName("EditiingScheduleTriggersCheckBox").Add_Checked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("EditiingScheduleTriggersCheckBox").Add_UnChecked({Set-ScheduleTriggersCheckBox})
    #$MainWindow.FindName("MonthlyScheduleCheckBox").Add_Checked({Set-ScheduleTriggersCheckBox})
    #$MainWindow.FindName("MonthlyScheduleCheckBox").Add_UnChecked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("WeeklyScheduleSundayCheckBox").Add_Checked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("WeeklyScheduleSundayCheckBox").Add_UnChecked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("WeeklyScheduleMondayCheckBox").Add_Checked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("WeeklyScheduleMondayCheckBox").Add_UnChecked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("WeeklyScheduleTuesdayCheckBox").Add_Checked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("WeeklyScheduleTuesdayCheckBox").Add_UnChecked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("WeeklyScheduleWednesdayCheckBox").Add_Checked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("WeeklyScheduleWednesdayCheckBox").Add_UnChecked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("WeeklyScheduleThursdayCheckBox").Add_Checked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("WeeklyScheduleThursdayCheckBox").Add_UnChecked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("WeeklyScheduleFridayCheckBox").Add_Checked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("WeeklyScheduleFridayCheckBox").Add_UnChecked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("WeeklyScheduleSaturdayCheckBox").Add_Checked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("WeeklyScheduleSaturdayCheckBox").Add_UnChecked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("MonthlyScheduleFirstCheckBox").Add_Checked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("MonthlyScheduleFirstCheckBox").Add_UnChecked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("MonthlyScheduleSecondCheckBox").Add_Checked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("MonthlyScheduleSecondCheckBox").Add_UnChecked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("MonthlyScheduleThirdCheckBox").Add_Checked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("MonthlyScheduleThirdCheckBox").Add_UnChecked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("MonthlyScheduleFourthCheckBox").Add_Checked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("MonthlyScheduleFourthCheckBox").Add_UnChecked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("MonthlyScheduleLastCheckBox").Add_Checked({Set-ScheduleTriggersCheckBox})
    $MainWindow.FindName("MonthlyScheduleLastCheckBox").Add_UnChecked({Set-ScheduleTriggersCheckBox})

    $MainWindow.FindName("FistLaunchCheckBox").DataContext = $CurrentConfig.FistLaunch
}
Function Global:Set-ScheduleTriggersCheckBox{
    If ($MainWindow.FindName("EditiingScheduleTriggersCheckBox").IsChecked){
        $MainWindow.FindName("WeeklyScheduleContainer").IsEnabled = $True
        $MainWindow.FindName("MonthlyScheduleContainer").IsEnabled = $True
    }
    Else{
        $MainWindow.FindName("NavigationBarCompleteButton").IsEnabled = $True
        $MainWindow.FindName("WeeklyScheduleContainer").IsEnabled = $False
        $MainWindow.FindName("MonthlyScheduleContainer").IsEnabled = $False
        Return
    }
    
    #$MainWindow.FindName("MonthlyScheduleFirstCheckBox").IsEnabled = $MainWindow.FindName("MonthlyScheduleCheckBox").IsChecked
    #$MainWindow.FindName("MonthlyScheduleSecondCheckBox").IsEnabled = $MainWindow.FindName("MonthlyScheduleCheckBox").IsChecked
    #$MainWindow.FindName("MonthlyScheduleThirdCheckBox").IsEnabled = $MainWindow.FindName("MonthlyScheduleCheckBox").IsChecked
    #$MainWindow.FindName("MonthlyScheduleFourthCheckBox").IsEnabled = $MainWindow.FindName("MonthlyScheduleCheckBox").IsChecked
    #$MainWindow.FindName("MonthlyScheduleLastCheckBox").IsEnabled = $MainWindow.FindName("MonthlyScheduleCheckBox").IsChecked

    #If (!($MainWindow.FindName("MonthlyScheduleCheckBox").IsChecked)){
    # $MainWindow.FindName("NavigationBarCompleteButton").IsEnabled = $True
    #}
    #Else
    If ($MainWindow.FindName("MonthlyScheduleFirstCheckBox").IsChecked -or
        $MainWindow.FindName("MonthlyScheduleSecondCheckBox").IsChecked -or $MainWindow.FindName("MonthlyScheduleThirdCheckBox").IsChecked -or
        $MainWindow.FindName("MonthlyScheduleFourthCheckBox").IsChecked -or $MainWindow.FindName("MonthlyScheduleLastCheckBox").IsChecked){
        $MainWindow.FindName("NavigationBarCompleteButton").IsEnabled = $True
    }
    #Else{
        #$MainWindow.FindName("NavigationBarCompleteButton").IsEnabled = $False
        #Return
    #}

    If ($MainWindow.FindName("WeeklyScheduleSundayCheckBox").IsChecked -or 
        $MainWindow.FindName("WeeklyScheduleMondayCheckBox").IsChecked -or $MainWindow.FindName("WeeklyScheduleTuesdayCheckBox").IsChecked -or 
        $MainWindow.FindName("WeeklyScheduleWednesdayCheckBox").IsChecked -or $MainWindow.FindName("WeeklyScheduleThursdayCheckBox").IsChecked -or 
        $MainWindow.FindName("WeeklyScheduleFridayCheckBox").IsChecked -or $MainWindow.FindName("WeeklyScheduleSaturdayCheckBox").IsChecked){
        $MainWindow.FindName("NavigationBarCompleteButton").IsEnabled = $True
    }
    Else{
        $MainWindow.FindName("NavigationBarCompleteButton").IsEnabled = $False
    }
}

#
# AboutTab
#
Function Global:Initialize-AboutTab{
    $MainWindow.FindName("FindLifecycleProductsHyperlink").Add_Click({param($sender,$e)
        Try{
            Start-Process $sender.NavigateUri
        }
        Catch{}
    })    
}