VBDesign is a ContentControl , which also implements IVBContent like VBVisual.
VBDesigns used to load and display styles of the category main (DUMain) and partial view (DULayout). Main views and partial views are required for business objects.When a business object is started, the iPlus framework first generates a root VB design and then loads the main view from the XAML parser . The main view is then assigned to the content property of the root VB design and the data context is set with the new business object. Finally, the root VB design is placed in the logical tree attached so that it is visually visible.
According to the nesting principle of designs , it does not make sense to pack the entire layout (XAML code) in one main view. Instead, main views should load additional partial views (sub- designs) by declaring "<VBDesign>" elements in the XAML code and specifying the name (ACIdentifier) of the sub-design with a preceding asterisk "*" in the VBContent property:
e.g. <Grid>...
<vb:VBDesign VBContent="*MyNameOfSubdesign"/>
...</Grid>
If no asterisk is prefixed , the VB content is interpreted as ACUrl and the path for a data binding is resolved. The property in the business object to be bound should be of type ACClassDesign. Thus, the business object can notify the VBDesign via PropertyChanged event that another design is to be loaded that is provided by the business object itself. With this technique you can implement e.g. a layout change at runtime in the style of Wizards .
If you place VBDesigns in the XAML code of partial views, you load additional partial views. Make sure that a partial view does not reload itself. There is no recursion check. Instead, a StackOverflow exception is thrown by the .NET framework.
When loading partial views, the data context is not changed , but is inherited from the root VBDesign via the logical tree. You change the data context yourself by declaring a binding to another property.
Child business objects
According to the composition pattern , business objects can again have child business objects. Business objects are usually loaded just-in-time when they are needed. A child business object can also be instantiated via VBDesign and integrated into the design of the parent business object as a "plug-in". You can do this with the <VBInstanceInfo> element:
...
<vb:VBDesign VBContent="*Mainlayout">
<vb:VBInstanceInfo Key="BSOAlarmMessengerConfig_Child"
ACIdentifier="BSOAlarmMessengerConfig_Child"
SetAsDataContext="True"
SetAsBSOACComponet="True"
AutoStart="True">
</vb:VBInstanceInfo>
</vb:VBDesign>
...
Several VBInstanceInfos can be declared within one VBDesign.
In the ACIdentifier property, enter the name of the child business object that you previously added to the development tree in the class tree. It is best to enter the same name in the Key field (it is used to clearly identify the IntanceInfo instance in the logical tree). If the SetAsDataContext property is set to True, the data context of the VBDesign is set with the child business object. The AutoStart property specifies whether the child business object should be instantiated at runtime if it does not already exist.
Important : By changing the data context via SetAsDataContext, you also change the context for searching the design , which is specified in the VBContent property. In the example above, the design "main layout" is searched for by the child business object and not by the parent BSO in which the above XAML code is declared.
Special feature: BSOACComponent
If you were careful, you may have wondered how can the relative addressing of the child business object actually work in VBInstanceInfo if it is possible to change the data context by binding the design of the parent business object?
You are right, this does not work either and therefore the property BSOACComponent is declared in the VBDesign's base class VBDesignBase:
public static readonly DependencyProperty BSOACComponentProperty =
ContentPropertyHandler.BSOACComponentProperty.AddOwner(
typeof(VBDesignBase),
new FrameworkPropertyMetadata(null,
FrameworkPropertyMetadataOptions.Inherits,
new PropertyChangedCallback(OnDepPropChanged))
);
Like the FrameworkElement.DataContext property, this property can be inherited in the logical tree. When loading from the root VBDesign, this property is also set and child business objects can then be addressed relatively - even if the data context is lost. For this reason, you should also set the "SetAsBSOACComponent" property to True in the VBInstanceInfo element, as you can see in the example above.