[Closed] dotnetobject "UserControl" Maximum Size
One of the biggest advantage of WPF is that you can insert any control to another control. this example shows you how you can do it:
TheWindow = dotnetobject "System.windows.Window"
TheWindow.width = 200
TheWindow.showintaskbar = false
TheWindow.show()
(dotnetobject "System.Windows.Interop.WindowInteropHelper" TheWindow).owner = dotnetobject "IntPtr" (windows.getMAXHWND())
fn CreateMatControl Name:"Mat" =
(
Item = dotnetobject "System.windows.controls.Label"
Item.content = Name
Item
)
fn CreateMultiMatControl Count:10 =
(
LV = dotnetobject "System.windows.controls.ListView"
LV.height = 150
LV.Width = 150
for i = 1 to Count do
(
Item = dotnetobject "System.windows.controls.Label"
Item.content = "Sub Mat " + i as string
LV.items.add Item
)
LV
)
MainLV = dotnetobject "System.windows.controls.ListView"
for i = 1 to 3 do MainLV.items.add (CreateMatControl Name:("Mat" + i as string))
MainLV.items.add (CreateMultiMatControl())
for i = 1 to 3 do MainLV.items.add (CreateMatControl Name:("Mat" + i as string))
TheWindow.content = MainLV
wow, that’s really great! Is it possible to put vertically(I mean one will be multimaterial and another with IDs) 2 subitems inside main item?
I’m not WPF expert, just beginner, but I can tell you some introductions:
WPF is newest UI solution from Microsoft.
You can make almost any UI with WPF.
In Windows Form, you have many limitations, for example you can not change TreeViewItem color, But in WPF you can change any property like background-foreground-border colors and style.
In WPF you can insert almost any control in another control.
There is couple ways you can use WPF inside 3dmax, one of them is like my examples. but other ways are more efficient.
Yes, add your items in to a StackPanel, change StackPanel orientation to horizontal.then set stackpanel as listviewitem.content
Actually you first need to know how WPF works, Then you can use it inside maxscript. Just google it, you can find many tutorials about it.
I already love WPF. Thank you so much. There is not much information about WPF and maxscript though…
Me too :), best practice is creating your UI inside Visual Studio, then you can execute xaml inside maxscript or more advanced method is creating assembly in C# and run it inside max.
OMG. Do you know any video tutorial of this? or at least well explained text tutorial?
No, but I can show you some examples,You can execute xaml inside max like this:
Xaml = "<ListViewItem
"
Xaml +=" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"
"
Xaml +=" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">
"
Xaml +=" <Grid>
"
Xaml +=" <Label Name=\"Part_Label\" Width=\"150\" />
"
Xaml +=" <TextBox Name=\"Part_TextBox\" Width=\"25\" />
"
Xaml +=" </Grid>
"
Xaml +=" </ListViewItem>
"
XamlReader = dotnetclass "System.Windows.Markup.XamlReader"
Item = XamlReader.Parse Xaml
and according to your example, this time we create ListViewItem by using xaml:
TheWindow = dotnetobject "System.windows.Window"
TheWindow.width = 200
TheWindow.showintaskbar = false
TheWindow.show()
(dotnetobject "System.Windows.Interop.WindowInteropHelper" TheWindow).owner = dotnetobject "IntPtr" (windows.getMAXHWND())
XamlReader = dotnetclass "System.Windows.Markup.XamlReader"
fn CreateMatItem Name:"Mat" ID:1 =
(
Xaml = "<ListViewItem
"
Xaml +=" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"
"
Xaml +=" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">
"
Xaml +=" <Grid>
"
Xaml +=" <Label Name=\"Part_Label\" Width=\"150\" />
"
Xaml +=" <TextBox Name=\"Part_TextBox\" Width=\"25\" />
"
Xaml +=" </Grid>
"
Xaml +=" </ListViewItem>
"
Item = XamlReader.Parse Xaml
(Item.findname "Part_Label").content = Name
(Item.findname "Part_TextBox").Text = ID as string
Item
)
fn CreateMultiMatItem Count:10 =
(
LV = dotnetobject "System.windows.controls.ListView"
LV.height = 150
LV.Width = 150
for i = 1 to Count do
(
LV.items.add (CreateMatItem Name:"Mat" ID:i)
)
LV
)
MainLV = dotnetobject "System.windows.controls.ListView"
for i = 1 to 3 do MainLV.items.add (CreateMatItem Name:"Mat" ID:i)
MainLV.items.add (CreateMultiMatItem())
TheWindow.content = MainLV
Thank you, Mehdi Zangeneh! I will try to play with this. This is really a good direction for study!