windowsforms-114785-controls-and-libraries-application-ui-manager-examples-how-to-populate-the-widget-view-in-code.md
This example demonstrates how to create and customize the WidgetView at runtime. In this example, the WidgetView contains two StackGroups, which host three Documents. Each Document displays different content in its normal and maximized states. StackGroups have relative lengths (their Length.UnitType properties are set to Star ), which allows them to dynamically resize whenever the parent form resizes.
Note
1. When creating the Widget View-based application at runtime, do not specify the DocumentManager.MdiParent property manually. Otherwise, widgets will not be displayed.
2. Be sure to set the DocumentManager.ContainerControl property after the View is created and assigned to the DocumentManager.View property.
//ucPreview.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WidgetViewExample {
public partial class ucPreview : UserControl {
public ucPreview() {
InitializeComponent();
}
}
}
//ucMaximizedContent.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WidgetViewExample {
public partial class ucMaximizedContent : UserControl {
public ucMaximizedContent() {
InitializeComponent();
}
}
}
//Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraBars.Docking2010;
using DevExpress.XtraBars.Docking2010.Views.Widget;
using DevExpress.XtraEditors;
namespace WidgetViewExample {
public partial class Form1 : XtraForm {
public Form1() {
InitializeComponent();
}
void Form1_Load(object sender, EventArgs e) {
AddDocumentManager();
for (int i = 0; i < 3; i++) {
AddDocuments();
}
//Adding Documents to group1 is not necessary, since all newly created Documents are automatically placed in the first StackGroup.
group1.Items.AddRange(new Document[] { view.Documents[0] as Document, view.Documents[1] as Document });
view.Controller.Dock(view.Documents[2] as Document, group2);
}
WidgetView view;
StackGroup group1, group2;
void AddDocumentManager() {
DocumentManager dM = new DocumentManager(components);
view = new WidgetView();
dM.View = view;
view.AllowDocumentStateChangeAnimation = DevExpress.Utils.DefaultBoolean.True;
group1 = new StackGroup();
group2 = new StackGroup();
group1.Length.UnitType = LengthUnitType.Star;
group1.Length.UnitValue = 2;
view.StackGroups.AddRange(new StackGroup[] { group1, group2 });
dM.ContainerControl = this;
}
int count = 1;
void AddDocuments() {
Document document = view.AddDocument(new ucPreview()) as Document;
document.MaximizedControl = new ucMaximizedContent();
count++;
}
}
}
'ucPreview.vb
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Namespace WidgetViewExample
Partial Public Class ucPreview
Inherits UserControl
Public Sub New()
InitializeComponent()
End Sub
End Class
End Namespace
'ucMaximizedContent.vb
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Namespace WidgetViewExample
Partial Public Class ucMaximizedContent
Inherits UserControl
Public Sub New()
InitializeComponent()
End Sub
End Class
End Namespace
'Form1.vb
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Imports DevExpress.XtraBars.Docking2010
Imports DevExpress.XtraBars.Docking2010.Views.Widget
Imports DevExpress.XtraEditors
Namespace WidgetViewExample
Partial Public Class Form1
Inherits XtraForm
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
AddDocumentManager()
For i As Integer = 0 To 2
AddDocuments()
Next i
'Adding Documents to group1 is not necessary, since all newly created Documents are automatically placed in the first StackGroup.
group1.Items.AddRange(New Document() { TryCast(view.Documents(0), Document), TryCast(view.Documents(1), Document) })
view.Controller.Dock(TryCast(view.Documents(2), Document), group2)
End Sub
Private view As WidgetView
Private group1, group2 As StackGroup
Private Sub AddDocumentManager()
Dim dM As New DocumentManager(components)
view = New WidgetView()
dM.View = view
view.AllowDocumentStateChangeAnimation = DevExpress.Utils.DefaultBoolean.True
group1 = New StackGroup()
group2 = New StackGroup()
group1.Length.UnitType = LengthUnitType.Star
group1.Length.UnitValue = 2
view.StackGroups.AddRange(New StackGroup() { group1, group2 })
dM.ContainerControl = Me
End Sub
Private count As Integer = 1
Private Sub AddDocuments()
Dim document As Document = TryCast(view.AddDocument(New ucPreview()), Document)
document.MaximizedControl = New ucMaximizedContent()
count += 1
End Sub
End Class
End Namespace