Can you implement Model-View-ViewModel using Powershell and WPF using PowerBoots?
Are there any examples of this? I haven't been able to find anything on google that shows how to implement this des开发者_如何学运维ign practice using powerboots.
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 ...
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)
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.
精彩评论