views:

76

answers:

2

Are there any examples of this? I haven't been able to find anything on google that shows how to implement this design practice using powerboots.

A: 

Well, I would have to work at that a bit to put together a real example, but let me give you a couple of hints to help you on your way ...

  1. You should work with the current source-control "tip" of PowerBoots, the dev keeps neglecting to release, but the code is solid (one downside: I think the current tip only has the dll for .Net4 64bit)

  2. You should consider using multiple windows in succession, or using pages to handle your "views"

With the latest version from source control, you can get away with something as simple as this:

# Create a ViewModel from your data (I'm hardcoding the data):
$data = new-object psobject -property @{ 
    Name = "John Brown"
    Age = 15
    HairColor = "Black"
}

# Create a View bound to that data ...
boots { 
  stackpanel -Margin 5 { 
    textbox -text { binding -path "Name" $data }
    textbox -text { binding -path "Age" $data }
    textbox -text { binding -path "HairColor" $data }
    button "OK" -margin 10 -On_Click { $this.Parent.Parent.Close() }
  }
}

# When that closes, any changes to the data are preserved ...
$data

Obviously that's not a full MVVM example, but hopefully it will get you on your way for now.

Jaykul
A: 

This is what I've been looking for! Another question though to extend this a bit further. I have a layout already made with blend. I don't want to rewrite it in Boots; by using -FileTemplateand Export-NamedControl, can I create Binding binding onLoad with boots?

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Name="Window"
    Title="MainWindow"
    Width="640" Height="480">

    <StackPanel>
        <TextBox Name="txtbox1"/>
        <TextBox Name="txtbox2"/>
        <TextBox Name="txtbox3"/>
    </StackPanel>
</Window>

$data = new-object psobject -property @{ Name = "John Brown";
                Age = 15; HairColor = "Black" }

$Window = New-BootsWindow {} -FileTemplate "C:\window.xaml" -async -passthru -On_Loaded {
   Export-NamedControl -Root $Args[0]
   $txtbox1.Text = "{ binding -path "Name" $data }"
}
foureight84