Use VS 2010 WPF Designer generated XAML with Show-UI

Nov 2, 2011 at 2:04 PM

I tried to work with Show-UI  folowing an old article :

I definitely want to design GUI with visual studio and then use that XAML in Show-UI , and not write it by hand.

The information in articele is outdated and examples  that come with Show-UI distribution dont show how to do this.

What is the right way to do it now ?

After research i tried :

[xml]$xaml_win = get-content $pwd\MainWindow_ps.xaml
Show-Window -Xaml $xaml_win

This ends in error :

Exception setting "Content": "Window must be the root of the tree. Cannot add Window as a child of Visual."
At C:\Users\domagoj\Documents\WindowsPowerShell\Modules\ShowUI\WPF\Show-Window.ps1:109 char:29
+                     $window. <<<< Content = $Control
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException


So I striped Window tag completely from XAML file, the I got :

Exception calling "Parse" with "1" argument(s): "'' XML namespace prefix does not map to a namespace URI, so cannot resolve property 'Name'. Line '2' Position '13'."
At C:\Users\domagoj\Documents\WindowsPowerShell\Modules\ShowUI\WPF\Show-Window.ps1:108 char:66
+                     $Control = [windows.Markup.XamlReader]::Parse <<<< ("$strWrite")
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException


Then I tryed to add : xmlns="" xmlns:x="" into first XML tag that left after striping windows tag, and then it worked, but is this the way it is intended to be done ???

Is there a updated article/documentation how to use VS 2010 generated XAML with Show-UI,  add event handlers etc...  ?


Here is my XAML test file ::::::::::::::::::::::::::::::::

    <TabControl Name="tabControl1" xmlns="" xmlns:x="">
        <TabItem Header="Korisnik" Name="tabItem1">
           <Grid HorizontalAlignment="Stretch" Name="GridMain" VerticalAlignment="Stretch">
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="73*" />
                <Grid  Name="grid1">
                        <RowDefinition Height="37" />
                        <RowDefinition Height="38" />
                        <RowDefinition Height="88" />
                        <ColumnDefinition Width="127*" />
                        <ColumnDefinition Width="540*" />
                        <ColumnDefinition Width="55*" />
                    <Label Content="Username" HorizontalAlignment="Right" Margin="14,0,0,0" Name="Username_label" VerticalAlignment="Top" />
                    <Label Content="Password" Grid.Row="1" HorizontalAlignment="Right" Margin="14,0,0,0" Name="label2" VerticalAlignment="Top" FontWeight="Normal" />
                    <TextBox Grid.Column="1" HorizontalAlignment="Stretch" Name="textBox1" VerticalAlignment="Stretch" Padding="1" Margin="3" />
                    <TextBox Grid.Column="1" Grid.Row="1" Name="textBox2" Margin="3" />
                    <Button Content="Kreiraj" Grid.Column="1" Grid.Row="2" Height="60" HorizontalAlignment="Left" Margin="0,10" Name="btn_kreiraj" VerticalAlignment="Top" Width="250" />

                <StackPanel Grid.Row="1" Height="35" Name="stackPanel2" Orientation="Horizontal" Margin="5">
                    <Image Name="img_poruka" Stretch="Fill" Source="/Argosy_AD_user_ADD;component/assets/Button-Check-icon.png" />
                    <Label Content="....." Name="lbl_poruka" />

                <Expander  Grid.Row="2" ToolTip="Log" Header="Log">
                <ScrollViewer Name="scrollViewer1" CanContentScroll="True">
                    <TextBlock Name="textBlock1" Text="Log ::::::::::::::::::" TextWrapping="Wrap" />
        <TabItem Header="Postavke" Name="tabItem2">
            <Grid />

Nov 3, 2011 at 3:25 AM
Edited Nov 3, 2011 at 3:26 AM

To be honest, this just doesn't work properly in ShowUI right now. It was on the list for the last release, and got dropped when we ran into a few unrelated problems and spent too much time on them.  ShowUI is (as you may have guessed) based largely on WPK and although we've improved on a lot of things over either WPK or PowerBoots, it hasn't gotten full parity with all the previous features ...

Nov 3, 2011 at 4:08 PM
Edited Nov 3, 2011 at 4:35 PM

I see there is other ways to use XAML in powershell (for example :

But I want to stick with Show-UI for now, I believe that you will add the feature back, it is a big timesaver.

I rewrote GUI by hand (everything works without New- prefix, only button doesnt) , it is still a lot faster if you start with xaml from vs 2010 and then translate by hand :

New-Window -WindowStartupLocation "CenterScreen" -Width 800 -Height 500 -Show {

TabControl -ControlName "tabControl1" {

    TabItem -Header "Korisnik" -Name tab1 { 
        Grid  -Rows Auto,Auto, 73* {
            Grid -Rows 37,38,88 -Columns 127*,540*,55* {
                Label -Content Username -Row 0 -Column 0
                Label -Content Password -Row 1 -Column 0
                TextBox -Name txt_username -Row 0 -Column 1
                TextBox -Name txt_pass -Row 1 -Column 1
                New-Button -Content Kreiraj -Name btn_kreiraj -Row 2 -Column 1 -Height 60 -HorizontalAlignment Left -VerticalAlignment Top -Width 250 -Margin "0,10"  -On_Click {           
                    $lbl_poruka.content = "TEST 777"
            StackPanel -Row 1 -Height 35 -Name stackPanel2 -Orientation Horizontal -Margin 5 {
                Image -Name img_ok -Stretch Fill -Source "assets\Button-Check-icon.png"
                Label -Content "..." -Name lbl_poruka
            Expander -Row 2 -ToolTip Log -Header Log {
                ScrollViewer -Name scrollViewer1 -CanContentScroll { 
                    TextBlock -Name textBlock1 -TextWrapping Wrap -Text "Log ::::::::::::::"
    TabItem -Header "Postavke" -ControlName tab2 {  Label -Content POSTAVKE    }