Adding UI to FlatRedBall
Last updated
Last updated
FlatRedBall plugins can add custom UI to Glue which are hosted in tabs. Tabs can be always visible or in response to events (such as when a file is selected). This tutorial will show how to create a tab that displays information about the selected file.
First we will create a WPF user control in our project:
Right-click on your project and select Add -> New Folder
Name the folder Controls
Right-click on the newly-created folder
Select Add -> New Item...
Select the Installed -> Visual C# Items -> WPF category
Select User Controls (WPF)
Enter the name MainControl (more complicated plugins may have multiple controls)
Click Add
To test the control, we will add a TextBlock at first. Modify the XAML code as shown in the following code:
Now we'll show the control whenever the user selects a file, but hide it whenever another object is selected. To do this, modify the MainTutorialPlugin.cs file as shown in the following snippet:
Let's break down some of the parts of the code above.
This is a delegate which is raised whenever an item is selected. Subscribing to this allows a plugin to perform custom logic when the user selects an item in the tree view. In this case, we will call the HandleItemSelected method. Glue plugins define dozens of delegates such as when a project is loaded, a file changes, or an object is added to an entity.
GlueState.Self provides information about the current state of Glue, including which objects are selected in the tree view. In this case we are checking if a file is selected, which would be represented by the CurrentReferencedFileSave member.
Removes the tab associated with this plugin from Glue - the tab will still be held in memory but it will not display.
AddToTab adds the argument control to the argument tab. In this case we are adding our main control to the center tab control. We only need to call this method once - after that the tab is associated with the center tab and we can call AddTab .
Rebuilding the plugin (make sure to build solution or explicitly select Build on the plugin project) will result in the tab being shown when a file is selected.