Hi all,
So i am building this simple GUI with PS WPF.
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName 'Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = @'
<Window
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"
Title="Notification" Name="Notification" Height="480" Width="680" Visibility="Visible" WindowStartupLocation="CenterScreen" Topmost="True" ResizeMode="NoResize" BorderThickness="1" WindowStyle="None" RenderTransformOrigin="0.5,0.5" AllowsTransparency="True" Background="Transparent">
<Window.Resources>
</Window.Resources>
<Border Background="White" BorderBrush="Gray" BorderThickness="1,1,1,1" CornerRadius="6,6,6,6">
<Grid>
<Label Name="labelMessage" HorizontalAlignment="Center" Margin="5,150,0,0" VerticalAlignment="Top" Height="60" Width="480" FontFamily="Metropolis" FontSize="14" Visibility="Visible">
<AccessText TextWrapping="WrapWithOverflow">
_Another long piece of text that requires text wrapping goes here.
</AccessText>
</Label>
</Grid>
</Border>
</Window>
'@
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
catch{Write-Host "Unable to load Windows.Markup.XamlReader. Some possible causes for this problem include: .NET Framework is missing PowerShell must be launched with PowerShell -sta, invalid XAML code was encountered."; exit}
$xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name)}
$Form.ShowDialog() | out-null
What i am struggling at the moment is adding background image to that form. I have tested with multiple different ways to do so and it fails every time:
- i tried:
<Window.Resources>
<ImageSource x:Key="imgSource">image_resource.jpg</ImageSource>
<ImageBrush x:Key="backgroundImage" ImageSource="{DynamicResource imgSource}" Opacity="0.3"></ImageBrush>
</Window.Resources>
- I also tried:
<Grid.Background>
<ImageBrush ImageSource="Images/background.jpg"/>
</Grid.Background>
Nothing seems to work as expected. I will appreciate if someone can point me in the correct direction for this issue.