We help IT Professionals succeed at work.

WPF and Powershell not displaying Image

Kelly Garcia
Kelly Garcia asked
on
387 Views
Last Modified: 2017-07-07
HI All,

I have written this code for a gui, it is not displaying the image, please help!

Add-Type -AssemblyName PresentationFramework

#Build the GUI
[xml]$Form = @"
<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    Name="Window" Title="MainWindow" WindowStartupLocation = "CenterScreen" 
    Height="410" Width="560" ShowInTaskbar = "True">

    <DockPanel>
        <StackPanel DockPanel.Dock="Left">
            <Button Name="GL" Content="GL" HorizontalAlignment="Left" Margin="10,10,10,10" VerticalAlignment="Top" Width="97" Height="41" Background="#DE0064" />
            <Button Name="EYL" Content="EYL" HorizontalAlignment="Left" Margin="10,10,10,10" VerticalAlignment="Top" Width="97" Height="41" RenderTransformOrigin="0.532,1.742" Background="#DE0064"  />
            <Button Name="HKL" Content="HKL" HorizontalAlignment="Left" Margin="10,10,10,10" VerticalAlignment="Top" Width="97" Height="41" Background="#DE0064" />
            <Button Name="UKL" Content="UKL" HorizontalAlignment="Left" Margin="10,10,10,10" VerticalAlignment="Top" Width="97" Height="41" Background="#DE0064"  />
            <Button Name="LPUK" Content="LPUK" HorizontalAlignment="Left" Margin="10,10,10,10" VerticalAlignment="Top" Width="97" Height="41" RenderTransformOrigin="0.532,1.742" Background="#DE0064"  />
            <Button Name="Demo" Content="Demo" HorizontalAlignment="Left" Margin="10,10,10,10" VerticalAlignment="Top" Width="97" Height="41" RenderTransformOrigin="0.532,1.742" Background="#DE0064" />
        </StackPanel>
        <Grid DockPanel.Dock="Top">
            <TextBox Name="Text" BorderThickness="0" HorizontalAlignment="Left" Height="271" Margin="10,10,10,10" Padding="5,10,5,10" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="397" />
            <Rectangle Width="{Binding ElementName=Text, Path=ActualWidth}" Height="{Binding ElementName=Text, Path=ActualHeight}" HorizontalAlignment="Left" Margin="10,10,10,10" StrokeDashArray="0.0 6.0 0.0" Stroke="Black" StrokeThickness="0.5" />
        </Grid>
		
        <Label Content="VM Deployment Utility" HorizontalAlignment="Left" Height="35" Margin="10,10.333,10,0" Padding="5,10,5,10" VerticalAlignment="Top" Width="178" />
        <Image Source="Thomas_logo.png" Height="41" Margin="0,39.333,0,0" VerticalAlignment="Top" Width="152" RenderTransformOrigin="-0.187,-0.135"/>
    	
	</DockPanel>
</Window>
"@ 

$NR= New-Object System.Xml.XmlNodeReader $Form
$Win = [Windows.Markup.XamlReader]::Load( $NR )

$GLButton = $Win.FindName("GL")
$GLButton.FontWeight = "Bold"
$GLButton.Foreground = "White"

$GLButton.Add_MouseEnter( {
    param (
        $sender,

        $eventArgs
    )

    $sender.FindName("Text").Text = 'Hovering over GL'
} )
$GLButton.Add_MouseLeave( {
    param (
        $sender,

        $eventArgs
    )

    $sender.FindName("Text").Text = ''
} )

$EYLButton = $Win.FindName("EYL")
$EYLButton.FontWeight = "Bold"
$EYLButton.Foreground = "White"
$EYLButton.Add_MouseEnter( {
    param (
        $sender,

        $eventArgs
    )

    $sender.FindName("Text").Text = 'Hovering over EYL'
} )

$HKLButton = $Win.FindName("HKL")
$HKLButton.FontWeight = "Bold"
$HKLButton.Foreground = "White"
$HKLButton.Add_MouseEnter( {
    param (
        $sender,

        $eventArgs
    )

    $sender.FindName("Text").Text = 'Hovering over HKL'
} )

$UKLButton = $Win.FindName("UKL")
$UKLButton.FontWeight = "Bold"
$UKLButton.Foreground = "White"
$UKLButton.Add_MouseEnter( {
    param (
        $sender,

        $eventArgs
    )

    $sender.FindName("Text").Text = 'Hovering over UKL'
} )


$LPUKButton = $Win.FindName("LPUK")
$LPUKButton.FontWeight = "Bold"
$LPUKButton.Foreground = "White"
$LPUKButton.Add_MouseEnter( {
    param (
        $sender,

        $eventArgs
    )

    $sender.FindName("Text").Text = 'Hovering over LPUKL'
} )

$DemoButton = $Win.FindName("Demo")
$DemoButton.FontWeight = "Bold"
$DemoButton.Foreground = "White"
$DemoButton.Add_MouseEnter( {
    param (
        $sender,

        $eventArgs
    )

    $sender.FindName("Text").Text = 'Hovering over Demo'
} )

$Win.Showdialog()

Open in new window


<Label Content="VM Deployment Utility" HorizontalAlignment="Left" Height="35" Margin="10,10.333,10,0" Padding="5,10,5,10" VerticalAlignment="Top" Width="178" />
        <Image Source="Thomas_logo.png" Height="41" Margin="0,39.333,0,0" VerticalAlignment="Top" Width="152" RenderTransformOrigin="-0.187,-0.135"/>

Open in new window


thank you in advance
Comment
Watch Question

Kelly GarciaSenior Systems Administrator

Author

Commented:
also when the end user clicks on a button I want it to open another wpf application, how do I do this?
PowerShell Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Kelly GarciaSenior Systems Administrator

Author

Commented:
it still isn't working, please help!
Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
Did you make the path to the image fully qualified in the end?
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.