Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Add-Type -AssemblyName PresentationFramework
- Add-Type -AssemblyName System.Windows.Forms
- Add-Type -AssemblyName WindowsBase
- Add-Type -AssemblyName PresentationCore
- # Build the XAML hashtable for everything
- $uiHash = [hashtable]::Synchronized(@{})
- #region The XAML Code
- [xml]$xaml = @'
- <Window x:Class="ExampleGUI"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:local="clr-namespace:ExampleGUI"
- DataContext="{Binding RelativeSource={RelativeSource Self}}"
- mc:Ignorable="d"
- Title="Example GUI" Height="450" Width="800">
- <Window.Background>
- <LinearGradientBrush StartPoint='0,0' EndPoint='0,1'>
- <LinearGradientBrush.GradientStops>
- <GradientStop Color='#C4CBD8' Offset='0' />
- <GradientStop Color='#E6EAF5' Offset='0.2' />
- <GradientStop Color='#CFD7E2' Offset='0.9' />
- <GradientStop Color='#C4CBD8' Offset='1' />
- </LinearGradientBrush.GradientStops>
- </LinearGradientBrush>
- </Window.Background>
- <Window.Resources>
- <!--Control colors.-->
- <Color x:Key="ControlNormalColor">#000000</Color>
- <Color x:Key="ControlMouseOverColor">#5E5E5E</Color>
- <Color x:Key="DisabledControlColor">#FFF2F2F2</Color>
- <Color x:Key="DisabledForegroundColor">#909098</Color>
- <Color x:Key="ControlPressedColor">#878787</Color>
- <Style x:Key="ButtonFocusVisual">
- <Setter Property="Control.Template">
- <Setter.Value>
- <ControlTemplate>
- <Border>
- <Rectangle Margin="2" StrokeThickness="1" Stroke="#60000000" StrokeDashArray="1 2" />
- </Border>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
- <!-- Button -->
- <Style TargetType="Button">
- <Setter Property="SnapsToDevicePixels" Value="true" />
- <Setter Property="OverridesDefaultStyle" Value="False" />
- <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}" />
- <!--<Setter Property="MinHeight" Value="29px" />
- <Setter Property="MinWidth" Value="103px" />-->
- <Setter Property="Foreground" Value="#FFFFFFFF" />
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="Button">
- <Border TextBlock.Foreground="{TemplateBinding Foreground}" x:Name="Border">
- <Border.Background>
- <SolidColorBrush Color="{DynamicResource ControlNormalColor}" />
- </Border.Background>
- <VisualStateManager.VisualStateGroups>
- <VisualStateGroup x:Name="CommonStates">
- <VisualStateGroup.Transitions>
- <VisualTransition GeneratedDuration="0:0:0.5" />
- <VisualTransition GeneratedDuration="0" To="Pressed" />
- </VisualStateGroup.Transitions>
- <VisualState x:Name="Normal" />
- <VisualState x:Name="MouseOver">
- <Storyboard>
- <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)"
- Storyboard.TargetName="Border">
- <EasingColorKeyFrame KeyTime="0" Value="{StaticResource ControlMouseOverColor}" />
- </ColorAnimationUsingKeyFrames>
- </Storyboard>
- </VisualState>
- <VisualState x:Name="Pressed">
- <Storyboard>
- <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)"
- Storyboard.TargetName="Border">
- <EasingColorKeyFrame KeyTime="0" Value="{StaticResource ControlPressedColor}" />
- </ColorAnimationUsingKeyFrames>
- </Storyboard>
- </VisualState>
- <VisualState x:Name="Disabled">
- <Storyboard>
- <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)"
- Storyboard.TargetName="Border">
- <EasingColorKeyFrame KeyTime="0" Value="{StaticResource DisabledControlColor}" />
- </ColorAnimationUsingKeyFrames>
- <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)"
- Storyboard.TargetName="Border">
- <EasingColorKeyFrame KeyTime="0" Value="{StaticResource DisabledForegroundColor}" />
- </ColorAnimationUsingKeyFrames>
- </Storyboard>
- </VisualState>
- </VisualStateGroup>
- </VisualStateManager.VisualStateGroups>
- <ContentPresenter Margin="2"
- HorizontalAlignment="Center"
- VerticalAlignment="Center"
- RecognizesAccessKey="True" />
- </Border>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
- </Window.Resources>
- <Grid>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="100" />
- <ColumnDefinition />
- </Grid.ColumnDefinitions>
- <TextBox x:Name="CodeBlock" Grid.Column="1"
- VerticalAlignment="Top" HorizontalAlignment="Left"
- TextWrapping="NoWrap" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible"/>
- <Button Content="Reset" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100"
- x:Name="ResetBtn" Height="40" IsEnabled="False"/>
- </Grid>
- </Window>
- '@ -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
- $reader = New-Object System.Xml.XmlNodeReader -ArgumentList $xaml
- $uiHash.Window = [System.Windows.Markup.XamlReader]::Load($reader)
- $xaml.SelectNodes("//*[@Name]") | ?{$_.Name -notlike "*lbl" -and $_.Name -ne "label" -and $_.Name -notlike "*Color*"} | %{
- $uiHash.Add($_.Name,$uiHash.Window.FindName($_.Name))
- }
- #endregion
- $uiHash.NotSet = $true
- # Event for clicking the Reset Button
- $uiHash.ResetBtn.Add_Click({
- $uiHash.NotSet = $true
- $uiHash.CodeBlock.Text = [string]::Empty
- $uiHash.ResetBtn.IsEnabled = $false
- })
- # Event for when the mouse enters the text box
- $uiHash.CodeBlock.Add_MouseEnter({
- if ($uiHash.NotSet)
- {
- # Reads the Clipboard only if it's a file that's copied.
- $file = Get-Clipboard -Format FileDropList -ErrorAction SilentlyContinue
- if ($null -ne $file)
- {
- # If it's a file, then we try to the read the text contents
- $text = Get-Content -Path $file.FullName -Raw -ErrorAction SilentlyContinue
- if (-not [string]::IsNullOrEmpty($text))
- {
- # If there's content read, then we populate the textbox with it.
- $uiHash.CodeBlock.Text = $text
- $uiHash.NotSet = $false
- $uiHash.ResetBtn.IsEnabled = $true # Enable the Reset Button so the user do this again.
- }
- }
- }
- })
- $uiHash.Window.ShowDialog() > $null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement