MAXScript Tools and Interaction with 3ds Max > Creating MAXScript Tools > XAML User Interface Definitions and MAXScript >

# XAML Files with MAXScript Controls

The Extensible Application Markup Language (XAML) is used to write Windows Presentation Foundation (WPF) applications.

XAML files are used to define the content of the Ribbon and of the Application Menu of 3ds Max 2010 and higher.

In 3ds Max 2010, XAML files had to be edited manually to modify existing features or add new ones.

Since 3ds Max 2011, the XAML files of the Ribbon interface can be customized using dedicated tools.

Several MAXScript controls can be included in the XAML code to integrate features like MacroScripts, spinners and color pickers.

## ActionItem in an XAML File

A MacroScript, which technically defines an ActionItem, can be added to the Application Menu using the following syntax:

    {wpfmax:ActionItem MacroCategory=<Category>, MacroName=<MacroScriptName> }

EXAMPLE:
For example, to add a new option to the Application Menu > Export sub-menu to write the scene to the 3 rd party BFF file format, you could add the following to the \ui\ApplicationMenu.xaml file inside the definition starting with the header <ApplicationMenuItem Text="Export" IsSplit="true" Id="ExportSplit" ...
    <ApplicationMenuItem Text="Bobo's File Format" Id="BFFExp" KeyTip="B"
    LargeImage="Icons/ApplicationMenu/export_32.ico"
    Description="Exports the scene in the MAXScript-based BFF format."
    CommandHandler="{wpfmax:ActionItem MacroCategory=Bobo_s Tools, MacroName=BFF_Exporter}"/>
After re-saving the XAML file, opening the3ds Max Application Menu shows the following additional command:

## Spinner in an XAML File

Afloat or integer Spinner control can be defined in the Ribbon's XAML file. The spinner will interact with the scene via a set of two callback functions defined in a struct.

Syntax:

    <wpfmax:MaxSpinnerFloat Id=<string>ID 	 MinWidth=<string>MinWidth 	 Width=<string>Width 	 Height=<string>Height 	 Min=<string>MinValur 	 Max=<string>MaxValue 	 Scale=<string>ScaleValue 	 init=<string>InitValue 	 ToolTip=<string>Tooltip 	 MaxscriptCallback=<string>ColorSwatchCallbackStruct />

    <wpfmax:MaxSpinnerInt Id=<string>ID   MinWidth=<string>MinWidth   Width=<string>Width   Height=<string>Height   Min=<string>MinValue   Max=<string>MaxValue   Scale=<string>ScaleValue   init=<string>InitValue   ToolTip=<string>Tooltip   MaxscriptCallback=<string>ColorSwatchCallbackStruct />

EXAMPLE:
Here is the sample to define a float spinner that could change the radius of an object like a sphere or a teapot:
XAML CODE:
    <wpfmax:MaxSpinnerFloat Id="FloatSpinnerSample" MinWidth="40" Width="40" Height="16"
    min="0.0" max="10000.0"
    scale="1.0"
    init="1.0"
    MaxscriptCallback="MySpinnerFloat"/>
MAXSCRIPT CODE:
     --Define a global struct with two functions - OnChange() and GetValue() --These will be called by the Ribbon spinner thanks to the --MaxscriptCallback definition:
    struct MySpinnerFloat
    (
    fn OnChanged Value = (
    for o in selection where is Property o #radius do o.radius = Value
    ),
    fn GetValue = (
    if selection.count > 0 then
    for o in selection where is Property o #radius do return o.radius
    else
    0
    )
    )
    --The OnChanged() function will be called when the value in the UI is changing. --The GetValue() function will be called when the system needs to update the value in the UI.

## Colorpicker in an XAML File

A ColorPicker UI Controls can be defined in the Ribbon's XAML file. The ColorPicker will interact with the scene via a set of two callback functions defined in a struct.

Syntax:

    <wpfmax:MaxRibbonColorSwatch Id="ID" MinWidth=<string>MinWidth Width=<string>Width Height=<string>Height MaxscriptCallback=<string>ColorSwatchCallbackStruct />

## MAXScript Command in an XAML File

A MAXScript Command call can be defined in the Ribbon's XAML file. The command can be any valid MAXScript expression.

Syntax:

    <wpfmax:MaxscriptCommand Maxscript=<string>Expression MaxscriptToggleOff=<string>OffExpression />

EXAMPLE:
Here is the actual code of the Border Sub-Object button in the Ribbon. When the button is toggled on, the MAXScript command "subObjectLevel = 3" is called to set the Border mode. When the button is toggled off, the MAXScriptToggleOff expression "subObjectLevel= 0" is called. The rest of the code defines which panels should be made visible when the toggle is on or off.
XAML CODE:
    <wpfmax:MaxSubjectobjectToggleButton Id="mBordermode" Text="Border" Mode="Border" Orientation="Vertical" ShowText="False" Size="Standard" Image="Icons/Modeling/bordermode_editpolygons.ico" >
    <wpfmax:MaxSubjectobjectToggleButton.CommandHandler>
    <wpfmax:MaxscriptCommand Maxscript="subobjectLevel = 3" MaxscriptToggleOff="subobjectLevel = 0" />
    </wpfmax:MaxSubjectobjectToggleButton.CommandHandler>
    <s:String>AUseSS, EModifyPanel, ESelectPanel, ESelectLoopsPanel, ESelectByPanel, AStorePanel, ANamedSetsPanel, APatternsPanel</s:String>
    <s:String>BBorderEdgesPanel, ETriangulationPanel, VGeometryPanel, VCutsPanel, VAlignPanel, VSubdivisionPanel, VPaintDeformPanel, OPropertiesPanel</s:String>
    </wpfmax:MaxSubjectobjectToggleButton>