function Load_main {
    param ($root)

[XML]$Form = @"
<?xaml encoding="utf-8"?>
<Window 
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                Name="Window" Title="HDS Admin Panel - Hauptfenster" Height="454" Width="1020" Icon="{Binding Icon}" ResizeMode="NoResize" WindowStyle="None">
    <Window.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="#0082c6"/>
        <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="#022335"/>
    </Window.Resources>
    <Grid Background="#00344E">
        <Image Name="Laufwerk" HorizontalAlignment="Left" Height="104" Margin="0,359,0,0" VerticalAlignment="Top" Width="110" Source="Binding" RenderTransformOrigin="0.409,0.857"/>
        <Label Name="version" Content="HDS Admin Panel" HorizontalAlignment="Left" Margin="87,379,0,0" VerticalAlignment="Top" Height="36" Width="186" FontSize="16" Foreground="White"/>
        <TextBox Name="tblaufwerkauslastung" BorderThickness="0" HorizontalAlignment="Left" Height="22" Margin="87,411,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="263" Background="#013C5A" Foreground="White" IsReadOnly="True" FontSize="14" IsTabStop="False"/>
        <Label Content="Log Admin Panel" HorizontalAlignment="Left" Margin="750,64,0,0" VerticalAlignment="Top" Height="369" Width="254" Background="#013C5A" Foreground="White" FontSize="16" FontWeight="Bold" HorizontalContentAlignment="Center"/>
        <Button TabIndex="4" Name="btnrefresh" Content="Clear Log" BorderThickness="0" HorizontalAlignment="Left" Margin="759,95,0,0" VerticalAlignment="Top" Width="237" Height="36" FontSize="13" Background="#00b8d4" Foreground="White" FontWeight="Medium">
            <Button.Resources>
                <Style TargetType="Border">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" Name="btnScanner" Content="Very dark void" BorderThickness="0" HorizontalAlignment="Left" Margin="26,17,0,0" VerticalAlignment="Top" Width="218" Height="42" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="Border">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Label Content="Administartion tool for the managing and manual handling of scripts created by Florian Spaeth.&#xA;It just needs to run! Nothing more or less. You understand me?!?. " HorizontalAlignment="Left" Margin="249,12,0,0" VerticalAlignment="Top" Width="755" Height="52" FontSize="15" Foreground="White"/>
        <Label Name="log" Content="" HorizontalAlignment="Left" Margin="759,138,0,0" VerticalAlignment="Top" Width="237" Height="284" FontSize="12" Foreground="White"/>
        <Button TabIndex="1" Name="btninfo" HorizontalAlignment="Left" Margin="971,22,0,0" VerticalAlignment="Top" Width="30" Height="30" Background="Transparent" ToolTip="Information" BorderThickness="0">
            <Image Name="imginfo" Source="{Binding}"/>
            <Button.Resources>
                <Style TargetType="Border">
                    <Setter Property="CornerRadius" Value="5"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btnMEG"  Content="Gaming" BorderThickness="0" HorizontalAlignment="Left" Margin="28,85,0,0" VerticalAlignment="Top" Width="118" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btnr710" Content="R710" BorderThickness="0" HorizontalAlignment="Left" Margin="172,85,0,0" VerticalAlignment="Top" Width="120" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btnITM" Content="ITM" BorderThickness="0" HorizontalAlignment="Left" Margin="320,85,0,0" VerticalAlignment="Top" Width="118" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White" HorizontalContentAlignment="Center">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btnScanner_Kopieren3" Content="Empty" BorderThickness="0" HorizontalAlignment="Left" Margin="464,85,0,0" VerticalAlignment="Top" Width="120" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btnScanner_Kopieren4" Content="Empty" BorderThickness="0" HorizontalAlignment="Left" Margin="610,85,0,0" VerticalAlignment="Top" Width="120" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btnScanner_Kopieren5" Content="Empty" BorderThickness="0" HorizontalAlignment="Left" Margin="28,159,0,0" VerticalAlignment="Top" Width="118" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btnScanner_Kopieren6" Content="Empty" BorderThickness="0" HorizontalAlignment="Left" Margin="172,159,0,0" VerticalAlignment="Top" Width="120" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btnScanner_Kopieren7" Content="Empty" BorderThickness="0" HorizontalAlignment="Left" Margin="320,159,0,0" VerticalAlignment="Top" Width="118" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btnScanner_Kopieren8" Content="Empty" BorderThickness="0" HorizontalAlignment="Left" Margin="464,159,0,0" VerticalAlignment="Top" Width="120" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btnScanner_Kopieren9" Content="Empty" BorderThickness="0" HorizontalAlignment="Left" Margin="610,159,0,0" VerticalAlignment="Top" Width="120" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btnScanner_Kopieren10" Content="Empty" BorderThickness="0" HorizontalAlignment="Left" Margin="28,231,0,0" VerticalAlignment="Top" Width="118" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btnScanner_Kopieren11" Content="Empty" BorderThickness="0" HorizontalAlignment="Left" Margin="172,231,0,0" VerticalAlignment="Top" Width="120" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btnScanner_Kopieren12" Content="Empty" BorderThickness="0" HorizontalAlignment="Left" Margin="320,231,0,0" VerticalAlignment="Top" Width="118" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btnScanner_Kopieren13" Content="Empty" BorderThickness="0" HorizontalAlignment="Left" Margin="464,231,0,0" VerticalAlignment="Top" Width="120" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btnScanner_Kopieren14" Content="Empty" BorderThickness="0" HorizontalAlignment="Left" Margin="610,231,0,0" VerticalAlignment="Top" Width="120" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btnScanner_Kopieren15" Content="Empty" BorderThickness="0" HorizontalAlignment="Left" Margin="28,307,0,0" VerticalAlignment="Top" Width="118" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btnScanner_Kopieren16" Content="Empty" BorderThickness="0" HorizontalAlignment="Left" Margin="172,307,0,0" VerticalAlignment="Top" Width="120" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btnScanner_Kopieren17" Content="Empty" BorderThickness="0" HorizontalAlignment="Left" Margin="320,307,0,0" VerticalAlignment="Top" Width="118" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btngetlogs" Content="Get Logs" BorderThickness="0" HorizontalAlignment="Left" Margin="464,307,0,0" VerticalAlignment="Top" Width="120" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Button TabIndex="0" x:Name="btnclrtmp" Content="Clear tmp" BorderThickness="0" HorizontalAlignment="Left" Margin="610,307,0,0" VerticalAlignment="Top" Width="120" Height="50" FontSize="16" FontWeight="Bold" Background="#00b8d4" Foreground="White">
            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="2"/>
                </Style>
            </Button.Resources>
        </Button>
        <Label Content="" HorizontalAlignment="Left" Margin="1017,0,0,0" VerticalAlignment="Center" Height="454" Width="3" Background="DarkGray" Foreground="White" FontSize="16" FontWeight="Bold" HorizontalContentAlignment="Center"/>
        <Label Content="" HorizontalAlignment="Left" VerticalAlignment="Center" Height="454" Width="3" Background="DarkGray" Foreground="White" FontSize="16" FontWeight="Bold" HorizontalContentAlignment="Center"/>
        <Label Content="" HorizontalAlignment="Center" VerticalAlignment="Top" Height="3" Width="1020" Background="DarkGray" Foreground="White" FontSize="16" FontWeight="Bold" HorizontalContentAlignment="Center" Margin="0,451,0,0"/>
        <Label Content="" HorizontalAlignment="Center" VerticalAlignment="Top" Height="3" Width="1020" Background="DarkGray" Foreground="White" FontSize="16" FontWeight="Bold" HorizontalContentAlignment="Center"/>
    </Grid>
</Window>
"@
    
    # Lädt das Fenster
    $window=[Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $Form))
    $NR=(New-Object System.Xml.XmlNodeReader $Form)
    $window=[Windows.Markup.XamlReader]::Load($NR)

    # Objekt - Variablen Verknüpfung
    $Laufwerk = $window.findName("Laufwerk")
    $Script:mainimgswitch = $window.findName("imgswitch")
    $imginfo = $window.findName("imginfo")
    $Script:bar = $window.findName("pbbar")
    $Script:last = $window.findName("tblaufwerkauslastung")
    $Script:mainscanner = $window.findName("btnScanner")
    $Script:maininfo = $window.findName("btninfo")
    $Script:mainloading = $window.findName("pbLoading")
    $Script:btn_logchange = $window.findName("btnfiltersw")
    $Script:btn_MEG = $window.findName("btnMEG")
    $Script:btn_itm = $window.findName("btnITM")
    $Script:btn_r710 = $window.findName("btnr710")
    $Script:btn_getlogs = $window.findName("btngetlogs")
    $Script:btn_logrefresh = $window.findName("btnrefresh")
    $Script:main_log = $window.findname("log")
    $Script:main_version = $window.findname("version")

    # Verknüpft feste Elemente
    $window.Title = $Script:Version
    $window.icon="$root/Source/Logo.png"
    $Laufwerk.Source = "$root/Source/HDD1.png"
    $imginfo.Source = "$root/Source/info.png"
    $last.Text = "Current User: $Env:UserName"
    $main_version.Content = "$Script:Version"
    $btn_MEG.ToolTip = "Zero configuration Tool for DELL iDrac`nAccount _autcert needed"
    $btn_ITM.ToolTip = "Certificate distributor for DELL iDrac`nAccount _hardcon needed"
    $btn_R710.ToolTip = "Collection of Tools for DEFU Database`nAccount _DellFirmwareUpdates needed"
    $btn_getlogs.ToolTip = "Collection of all Logs known to this Script"

    return $window
}

$Script:main = Load_main $args[0]       # Variable: $main

$btn_logrefresh.Add_Click({
    $main_log.content = ""
    Write-Admin-Log "Clear GUI Log"
})

$mainscanner.Add_Click({
    $main.Hide()
    Write-Admin-Log "Seik"
})

$btn_ITM.Add_Click({
    Write-Admin-Log "open cert windows"
})

$btn_MEG.Add_Click({
    Write-Admin-Log "open Gaming window"
    $gaming.ShowDialog() | Out-Null
})

$btn_R710.Add_Click({
    Write-Admin-Log "open R710 window"
    $r710.ShowDialog() | Out-Null
})

$btn_getlogs.Add_Click({
    Write-Admin-Log "open get logs window"
    $getlog.ShowDialog() | Out-Null
})

$maininfo.Add_Click({
    $info.ShowDialog() | Out-Null
})

$main.Add_MouseLeftButtonDown({
    $main.DragMove()
})
