|
|
@@ -0,0 +1,150 @@
|
|
|
+
|
|
|
+[xml]$XAML_TEXTDIALOG = @"
|
|
|
+<Window
|
|
|
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
|
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
|
+ xmlns:xc="clr-namespace:ExCastle.Wpf"
|
|
|
+ Title="Input" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen">
|
|
|
+ <Grid Margin="15">
|
|
|
+ <Grid.ColumnDefinitions>
|
|
|
+ <ColumnDefinition Width="Auto" />
|
|
|
+ <ColumnDefinition Width="*" />
|
|
|
+ </Grid.ColumnDefinitions>
|
|
|
+ <Grid.RowDefinitions>
|
|
|
+ <RowDefinition Height="Auto" />
|
|
|
+ <RowDefinition Height="Auto" />
|
|
|
+ <RowDefinition Height="Auto" />
|
|
|
+ </Grid.RowDefinitions>
|
|
|
+
|
|
|
+ <Label Name="lblQuestion" Grid.Column="1">Question:</Label>
|
|
|
+ <TextBox Name="txtAnswer" Grid.Column="1" Grid.Row="1" MinWidth="250">Answer</TextBox>
|
|
|
+
|
|
|
+ <WrapPanel Grid.Row="2" Grid.ColumnSpan="2" HorizontalAlignment="Right" Margin="0,15,0,0">
|
|
|
+ <Button IsDefault="True" Name="btnDialogOk" MinWidth="60" Margin="0,0,10,0">_Ok</Button>
|
|
|
+ <Button IsCancel="True" MinWidth="60">_Cancel</Button>
|
|
|
+ </WrapPanel>
|
|
|
+ </Grid>
|
|
|
+</Window>
|
|
|
+"@
|
|
|
+
|
|
|
+[xml]$XAML_BYTESIZEDIALOG = @"
|
|
|
+<Window
|
|
|
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
|
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
|
+ xmlns:xc="clr-namespace:ExCastle.Wpf"
|
|
|
+ Title="Input" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen">
|
|
|
+ <Grid Margin="15">
|
|
|
+ <Grid.ColumnDefinitions>
|
|
|
+ <ColumnDefinition Width="Auto" />
|
|
|
+ <ColumnDefinition Width="*" />
|
|
|
+ </Grid.ColumnDefinitions>
|
|
|
+ <Grid.RowDefinitions>
|
|
|
+ <RowDefinition Height="Auto" />
|
|
|
+ <RowDefinition Height="Auto" />
|
|
|
+ <RowDefinition Height="Auto" />
|
|
|
+ </Grid.RowDefinitions>
|
|
|
+
|
|
|
+
|
|
|
+ <Label Name="lblQuestion" Grid.Column="1">Enter Size in:</Label>
|
|
|
+ <WrapPanel Grid.Row="1" Grid.ColumnSpan="2" HorizontalAlignment="Right" Margin="0,15,0,0">
|
|
|
+ <TextBox Name="txtAnswer" Grid.Column="1" Grid.Row="1" MinWidth="250">512</TextBox>
|
|
|
+ <ComboBox Name="sizeScale">
|
|
|
+ <ComboBoxItem>B</ComboBoxItem>
|
|
|
+ <ComboBoxItem>512B</ComboBoxItem>
|
|
|
+ <ComboBoxItem>KB</ComboBoxItem>
|
|
|
+ <ComboBoxItem IsSelected="True">MB</ComboBoxItem>
|
|
|
+ <ComboBoxItem>GB</ComboBoxItem>
|
|
|
+ </ComboBox>
|
|
|
+ </WrapPanel>
|
|
|
+
|
|
|
+ <WrapPanel Grid.Row="2" Grid.ColumnSpan="2" HorizontalAlignment="Right" Margin="0,15,0,0">
|
|
|
+ <Button IsDefault="True" Name="btnDialogOk" MinWidth="60" Margin="0,0,10,0">_Ok</Button>
|
|
|
+ <Button IsCancel="True" MinWidth="60">_Cancel</Button>
|
|
|
+ </WrapPanel>
|
|
|
+ </Grid>
|
|
|
+</Window>
|
|
|
+"@
|
|
|
+
|
|
|
+# $XAML = $XAML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window' #-replace wird benötigt, wenn XAML aus Visual Studio kopiert wird.
|
|
|
+#XAML laden
|
|
|
+[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
|
|
|
+
|
|
|
+Function LoadWPF($XAML){
|
|
|
+ $app = @{
|
|
|
+ Form = [Windows.Markup.XamlReader]::Load( (New-Object System.Xml.XmlNodeReader $XAML) )
|
|
|
+ WPF = @{}
|
|
|
+ }
|
|
|
+ $xaml.SelectNodes("//*[@Name]") | %{$app.WPF | Add-Member -MemberType NoteProperty -Name $_.Name -Value $app.Form.FindName($_.Name)}
|
|
|
+ $app
|
|
|
+}
|
|
|
+
|
|
|
+Function ByteSizeDialog
|
|
|
+{
|
|
|
+ param(
|
|
|
+ [int]$default = 536870912
|
|
|
+ )
|
|
|
+ $MyApp = LoadWPF $XAML_BYTESIZEDIALOG
|
|
|
+ $MyApp.WPF.txtAnswer.SelectAll() | Out-Null
|
|
|
+ $MyApp.WPF.txtAnswer.Focus() | Out-Null
|
|
|
+
|
|
|
+ $MyApp.WPF.txtAnswer.Add_PreviewTextInput({
|
|
|
+ $event = $_
|
|
|
+ try{
|
|
|
+ $val = ([int]$_.Text)
|
|
|
+ } catch {
|
|
|
+ $event.Handled = $true
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ $values = @(
|
|
|
+ 0,
|
|
|
+ 9,
|
|
|
+ 10,
|
|
|
+ 20,
|
|
|
+ 30
|
|
|
+ )
|
|
|
+
|
|
|
+ $MyApp.WPF.btnDialogOk.Add_Click({
|
|
|
+ $MyApp.Form.DialogResult = $true
|
|
|
+ $MyApp.Form.Close() | Out-Null
|
|
|
+ })
|
|
|
+
|
|
|
+ if ($MyApp.Form.ShowDialog()){
|
|
|
+ (([int]$MyApp.WPF.txtAnswer.Text) * [Math]::Pow(2,$values[$MyApp.WPF.SizeScale.selectedIndex]))
|
|
|
+ } else {
|
|
|
+ $false
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+Function TextDialog
|
|
|
+{
|
|
|
+ param(
|
|
|
+ $label = "Question:",
|
|
|
+ $default = "Some Default Text"
|
|
|
+ )
|
|
|
+
|
|
|
+ $MyApp = LoadWPF $XAML_TEXTDIALOG
|
|
|
+
|
|
|
+ $MyApp | Add-Member -NotePropertyName DialogResult -NotePropertyValue $false
|
|
|
+
|
|
|
+ $MyApp.WPF.txtAnswer.Text = $default
|
|
|
+ $MyApp.WPF.lblQuestion.Text = $label
|
|
|
+
|
|
|
+ $MyApp.WPF.txtAnswer.SelectAll()
|
|
|
+ $MyApp.WPF.txtAnswer.Focus()
|
|
|
+
|
|
|
+ # $MyApp.WPF.txtAnswer.Add_TextChanged({$this.Text | Out-Host})
|
|
|
+
|
|
|
+ $Form = $MyApp.Form
|
|
|
+ $MyApp.WPF.btnDialogOk.Add_Click({
|
|
|
+ $MyApp.Form.DialogResult = $true
|
|
|
+ $MyApp.Form.Close()
|
|
|
+ })
|
|
|
+ if ($MyApp.Form.ShowDialog()){
|
|
|
+ $MyApp.WPF.txtAnswer.Text
|
|
|
+ } else {
|
|
|
+ $false
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+Export-ModuleMember -Function *
|