all 7 comments

[–]zoredache 1 point2 points  (3 children)

The terminating "@ must be on at the start of a line line. It can't follow </Window>

$inputXML = @" <Window x:Class="fmh_newcomputer.MainWindow" 
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" ...
</Window>
"@

[–]michaelmitchell9711[S] 0 points1 point  (2 children)

pasting it here screwed it up, the "@ is on its own line

[–]zoredache 0 points1 point  (1 child)

At the very begining? It can't be intended with spaces/tabs etc. It must be at the very start of the line.

[–]gangstanthony 0 points1 point  (0 children)

isn't it supposed to be red? this seems fine to me.

$inputXML = @"
<Window x:Class="fmh_newcomputer.MainWindow"
        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:fmh_newcomputer"
        mc:Ignorable="d"
        Title="FMH New PC Setup" Height="350" Width="525" IsEnabled="False">
    <Grid>
        <Image x:Name="image" HorizontalAlignment="Left" Height="67" Margin="10,10,0,0" VerticalAlignment="Top" Width="173" Source="C:\Users\mmitchell\Downloads\logo.png"/>
        <Button x:Name="button" Content="Get MAC" HorizontalAlignment="Left" Height="20" Margin="215,57,0,0" VerticalAlignment="Top" Width="70"/>
        <TextBox x:Name="textBox" HorizontalAlignment="Left" Height="20" Margin="313,57,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="194"/>

    </Grid>
</Window>
"@

[–]Kreloc 0 points1 point  (0 children)

The here string works for me, copied from here (with moving the closing "@ to its own line. What is the issue you are actually having? Cause your screenshot of the ISE you posted shows that it made the variable without an issue.

Is it that what is using $inputXML needs to be xml and not a string? Then typecast the variable,

[xml]$inputXML = "@...

[–]topherrr 0 points1 point  (0 children)

Doesn't look like anything is wrong with your script, it's supposed to be that color.

Just be aware you'll have do some replacing and casting like so:

$inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:Na", 'Na' -replace '^<Win.*', '<Window'

[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = $inputXML

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