[Closed] 2 WPF Examples
Hey guys, I’ve been digging WPF stuff and I came up with two simple examples…for me it’s being fun to find out the new possibilities of this. Cheers.
dnWindow=dotnetobject "System.Windows.Window"
dnWindow.Title="WPF Test"
dnWindow.Height=200
dnWindow.Width=200
dnColor=dotnetobject "System.Windows.Media.SolidColorBrush"
dnColor.Color=(dotnetclass "System.Windows.Media.Colors").AliceBlue
dnCanvas=dotnetobject "System.Windows.Controls.Canvas"
dnCanvas.Background=dnColor
dnButton=dotnetobject "System.Windows.Controls.Button"
dnButton.Height=23
dnButton.Width=100
dnButton.Content="WPF Button Test"
dnCanvas.SetTop dnButton 10
dnCanvas.SetLeft dnButton 10
dnWindow.Content=dnCanvas
dnCanvas.Children.Add(dnButton)
dnWindow.Show()
XamlReader=dotnetclass "System.Windows.Markup.XamlReader"
XamlString="<Window
xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"
xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"
Title=\"Window1\" Height=\"300\" Width=\"300\">
<Grid>
<Button Height=\"22\" HorizontalAlignment=\"Left\" Margin=\"12,12,0,0\" Name=\"Button1\" VerticalAlignment=\"Top\" Width=\"87\">Button</Button>
<ComboBox Margin=\"0,12,12,0\" Name=\"ComboBox1\" Height=\"22\" VerticalAlignment=\"Top\" HorizontalAlignment=\"Right\" Width=\"122\" />
<ListBox Margin=\"12,58,12,12\" Name=\"ListBox1\" />
</Grid>
</Window>"
XamlWindow=XamlReader.Parse XamlString
XamlWindow.Show()
I find the second example to have great habilities in terms of UI design for maxscripts
cant get the 2nd example to work. I get this error:
– Unknown property: “Parse” in dotNetClass:System.Windows.Markup.XamlReader
I can see the potential though. Dotnet windows / controls from xml!
What Max version are you using? I’m using Max 2009 and they both work fine.
It’s not quite XML, it’s a little different, have a look here http://en.wikipedia.org/wiki/Windows_Presentation_Foundation and here http://en.wikipedia.org/wiki/Extensible_Application_Markup_Language
i’m using 2009 as well. am i supposed to load a some dotnet assembly first?
this error is much more fun
– Runtime error: dotNet runtime exception: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
( fresh max (2009×32) start )
Sorry guys, my bad. You have to install .NET 3.5 SP1 I guess that’s it… and I’m using Max 2009 64 bit btw.
ZeBoxx2: you had that error in both examples?
Cheers
Edit: About the Parse Method, this method is only available as .NET 3.5 SP1
yep, both examples – quite possibly I don’t have 3.5 (SP1 or otherwise) installed as of yet… will try later.
Shouldn’t we be building user interfaces in Adobe Flash, though?
Well, I ran into this because I was researching on how to create a windows form designer of my own but since I’m into it I guess I’ll try to do it WPF compatible, since the XAML parsing into maxscript seems like a good idea and it resolves the problem of having to convert VB code or VC to maxscript to actually create the controls. This way, after parsing the XAML code it returns the main Window, from where we can access all controls.
got the same errors as ZeBoxx2 with a fresh install of .NET 3.5 SP1 (2009×32 as well)
i’m guessing it’s an issue w/ 32 bit instead of 64
or maybe it’s an XP vs Vista thing (apparently WPF is a separate download for XP SP2) – no idea
I did / do have .NET 3.5 (SP1) installed… even tried re-installing, but the installer spends 5 minutes ‘preparing’, then pops up a dialog with a ton of knobs and buttons, then when going to install it just claims that Setup Failed