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
EDIT: You need to install .NET 3.5 SP1
Has anyone gotten the second example to work? Unfortinately I cannot get this to run in 3DS Max 2009 or 2010. I get this error:
dotNetObject:System.Windows.Window
-- Error occurred in anonymous codeblock; filename: ; position: 725; line: 4
-- Runtime error: dotNet runtime exception: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
I’m on XP32, with latest .NET 3.5 SP1 installed…
I was really hoping I could use XAML with Maxscript in this latest version, but I haven’t found a way yet. Even a way to make new ribbon bars would be nice.
[QUOTE=Kameleon;2663]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.
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
EDIT: You need to install .NET 3.5 SP1 :D[/QUOTE]
thats pretty cool. i’ve just started to look at wpf in max and ran across your examples. the above method worked well for me but i’m curious how you register events like buttons clicks or general changes in control states?
Hey John and thanks, but I have no ideia, since I’ve abandon this long time ago and never touched it again Sorry.
Please show us (if you can of course) the stuff you’ve been doing!
Cheers,
Artur Leão
Hey, I was poking a little bit on this and found that you can add event handlers in Xaml just by adding Click=“btnClickHandler” but this doesn’t work when parsing because the Xaml needs to be compiled first. The workaround is quite simple and not so different from what we do normally with dotNet controls. Just find the control after parsing the xaml and add the event handler in code. Here’s the example:
(
fn btn_Click =
(
print "You can do it!"
)
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
dotNet.addEventHandler XamlWindow.content.children.item[0] "Click" btn_Click
XamlWindow.Show()
)