Importing XAML from Visual Studio into Powersehll through ShowUI.

Sep 1, 2013 at 11:26 PM
Hi ShowUI forum,

By searching in the forum I can see that other people have asked for the feature of starting out the GUI in Visual Studio and then converting the XAML code to ShowUI powershell code. Has things changed now? Because the forum posts are two years old. And in these it is said that it was on your to-do list, but didn't get in.

I see there is cmdlets like: New-XamlXmlReaderSettings and New-XamlObjectReaderSettings in the ShowUI module. The help files on these are not that informative though. So I was hoping that someone in the forum might have info.

Looking forward to hear from you.

Thank you very much.

/Lars B.
Coordinator
Sep 3, 2013 at 5:40 AM
I took a long weekend this weekend, but I'm working on a new release for this week, so I'll try to make sure that the code I have for this gets into the samples for this release.
Sep 3, 2013 at 9:01 PM
Hi Jaykul,

Sounds great. Thank you, looking forward to that.
Sep 9, 2013 at 10:01 PM
Hi Jaykul....is the new release getting close :-D
Coordinator
Sep 10, 2013 at 3:06 AM
Yes. You can probably just grab the Show-UI function which is going to be the recommended way to create new UIs, and has the -Xaml switch. I might have a fix or two for that in an upcoming check-in (and I definitely have an example that I haven't pushed), but you can play with it if you like.

I basically have one thing left that I want to make work: the old (PowerBootsWPF-style) {Binding} syntax is working in 1.5, but it breaks on numerical parameters for various reasons, and I finally thought of an awesome fix for that, so you gotta wait for the release ;-)
Oct 14, 2013 at 10:59 PM
HI Jaykul,

I have tried to play around with the Show-UI function. I can't quite get it to work. Maybe I'm doing something wrong. I try to feed it an XAML file on the -xaml parameter.

// Say I have the below XAML file, started in Visual Studio and I want to use that for my GUI.

<Window x:Class="Gui.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="600" Width="800">
<DockPanel HorizontalAlignment="Left" Height="30" LastChildFill="False" VerticalAlignment="Top" Width="800">
    <Menu Height="30" VerticalAlignment="Top">
        <MenuItem Height="30" Width="40" Header="File">
            <Separator/>
            <MenuItem Header="E_xit" />
        </MenuItem>
        <MenuItem Height="30" Width="40" Header="Help">
            <MenuItem Header="About" />
        </MenuItem>
    </Menu>
</DockPanel>
</Window>

// Trying to feed that to the show-ui function gives me the following error "Show-UI : Cannot process argument transformation on parameter 'Xaml'. Cannot convert value "MY FILE" to type "System.Xml.XmlDocument". Error: "The specified node cannot be inserted as the valid child of this node, because the specified node is the wrong type."
To me the XAML file looks quite okay or am I wrong? At least, working with the project in Visual Studio does not give me any indications that it should be mal-programmed. Like compile-time errors and the like.

// Looking at the help for the show-ui function, you link to in your last post, in a PowerShell shell window tells me that some of the parameters are required. I just don't understand why I need to provide data for -Content & -Window when I have a XAML file from my Visual Studio GUI project to provide to the Show-UI function. With the XAML file it is my plan to define the window and so forth. So why should these two parameters be necessary?
I am hoping to do all the design/gui work in Visual Studio >> use the GUI project xaml file >> feed that too show-ui and see wonders. Is that possible?

I open for the possibility of me being totally nooby on this......all in all I really just want to make this work :-)

Have a nice day/evening.

/Lars B.
Coordinator
Oct 24, 2013 at 5:21 PM
I apologize for not getting this release out, and also for not answering for ten days -- I've been caught up in work, and another project which has a real-world deadline.

I pushed to the "develop" branch 2bb70772e913 which includes a fix for the code that enables loading loose xaml, a parameter fix for Show-UI, and a VisualStudioDesigner example with xaml and all.

Note that you still have to remove the "class" markup from the xaml after you edit it in Visual Studio.