After a dry spell, there’s now a couple of posts at once… 🙂
I have alluded to this in the past, but I thought I’d take the opportunity to provide a specific post on this topic.
The name itself is a little misleading, but…
To answer the question, it gives us access to the VisualTree, a tree that we can iterate up and down to our hearts content. How do I know this? A number of years ago I was working on a coolstorage program where I needed to explore the visual tree to provide some nifty effects. It was there that I learnt about WPF and how the interface objects were stored as a hierarchy and I gained a newfound respect for Microsoft and WPF!
Why am I going on about this – well, ScriptUtil.FindChild() will only go down the visual tree, not up it, so it is very helpful for us to know where in the scheme of things Smart Office grants us an entry point – then we will take that entry point and exploit the .Net framework 🙂
Probably the easiest way to demonstrate where the Controller.RenderEngine.Content sits in the visualtree is with a script:
import System; import System.Windows; import System.Windows.Controls; import MForms; package MForms.JScript { class testContent { public function Init(element: Object, args: Object, controller : Object, debug : Object) { var content : Object = controller.RenderEngine.Content; content.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Black); } } }
This script will simply set the background to black for the area that the .Content grid occupies. Nice, quick and easy.
As we can see the Sorting order isn’t within the black area, so passing controller.RenderEngine.Content to ScriptUtil.FindChild() will just return null. We have to walk up the tree to get to the sorting order.
This can be done with some code like so – this will take you all the way up the visual tree (I usually look for a standard control and iterate up the list until I hit that control).
var parent : Object = content var lastParent : Object = content; while(null != (parent = VisualTreeHelper.GetParent(parent))) { lastParent = parent; }
please can you write a full script to coloring sorting order level
If you take a look at this post
https://potatoit.wordpress.com/2010/10/23/exploring-the-smart-office-visual-tree-%E2%80%93-figuring-out-the-field-names-v2/
it demonstrates how to walk up the Visual Tree, then you will need to walk down the Visual Tree until you find the Sort Order.
Cheers,
Scott