<Window xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" x:Class="WpfApplication18.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="768" Width="1024" xmlns:my="clr-namespace:WpfApplication18" Loaded="Window_Loaded">
<Window.Resources>
<!--<DataTemplate x:Key="EmployeeNotes">
<Border>
<TextBlock Text="{Binding Path=Notes}" TextWrapping="Wrap" ></TextBlock>
</Border>
</DataTemplate>-->
</Window.Resources>
<Grid x:Name="mainGrid">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
<RowDefinition/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<!--region #GridDesignTime-->
<dxg:GridControl Grid.Row="0" Name="gridControl1" AutoGenerateColumns="AddNew" >
<dxg:GridControl.View>
<dxg:TableView DetailHeaderContent="Employees" AutoWidth="True" ShowGroupPanel="False" />
</dxg:GridControl.View>
<dxg:GridControl.DetailDescriptor>
<dxg:ContentDetailDescriptor HeaderContent="Notes">
<dxg:ContentDetailDescriptor.ContentTemplate>
<DataTemplate >
<Border>
<TextBlock Text="{Binding Path=Notes}" TextWrapping="Wrap" ></TextBlock>
</Border>
</DataTemplate>
</dxg:ContentDetailDescriptor.ContentTemplate>
</dxg:ContentDetailDescriptor>
</dxg:GridControl.DetailDescriptor>
</dxg:GridControl>
<!--endregion #GridDesignTime-->
<Button Grid.Row="3" Click="Button_Click">
<TextBlock Text="Create Second Grid in Code"></TextBlock>
</Button>
<GridSplitter Grid.Row="1" Height="10" Name="gridSplitter1" VerticalAlignment="Center" Width="Auto" ResizeDirection="Rows" HorizontalAlignment="Stretch" />
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DevExpress.Xpf.Grid;
namespace WpfApplication18
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
gridControl1.ItemsSource = Employees;
}
#region #GridInCode
private void Button_Click(object sender, RoutedEventArgs e)
{
GridControl newGrid = CreateGrid();
AddDetailsToGrid(newGrid);
Grid.SetRow(newGrid, 2);
mainGrid.Children.Add(newGrid);
}
private GridControl CreateGrid()
{
GridControl newGrid = new GridControl();
newGrid.AutoGenerateColumns = AutoGenerateColumnsMode.AddNew;
newGrid.View = new TableView();
(newGrid.View as TableView).AutoWidth = true;
(newGrid.View as TableView).ShowGroupPanel = false;
newGrid.View.DetailHeaderContent = "Employees";
newGrid.ItemsSource = Employees;
return newGrid;
}
private void AddDetailsToGrid(GridControl grid)
{
DataControlDetailDescriptor dataControlDetail = new DataControlDetailDescriptor();
dataControlDetail.ItemsSourcePath = "Orders";
GridControl detailGrid = new GridControl();
dataControlDetail.DataControl = detailGrid;
detailGrid.AutoGenerateColumns = AutoGenerateColumnsMode.AddNew;
detailGrid.View.DetailHeaderContent = "Orders";
(detailGrid.View as TableView).ShowGroupPanel = false;
ContentDetailDescriptor contentDetail = new ContentDetailDescriptor();
// contentDetail.ContentTemplate = (DataTemplate)FindResource("EmployeeNotes");
DataTemplate dt = new DataTemplate();
FrameworkElementFactory txFactory = new FrameworkElementFactory(typeof(TextBox));
txFactory.SetValue(TextBox.TextWrappingProperty, TextWrapping.Wrap);
txFactory.SetBinding(TextBox.TextProperty, new Binding("Notes"));
dt.VisualTree = txFactory;
contentDetail.ContentTemplate = dt;
contentDetail.HeaderContent = "Notes";
//TabViewDetailDescriptor tabDetail = new TabViewDetailDescriptor();
//tabDetail.DetailDescriptors.Add(dataControlDetail);
//tabDetail.DetailDescriptors.Add(contentDetail);
grid.DetailDescriptor = contentDetail;
}
#endregion #GridInCode
private List<Employee> employees;
private List<Employee> Employees
{
get
{
if (employees == null)
PopulateEmployees();
return employees;
}
}
private void PopulateEmployees()
{
employees = new List<Employee>();
employees.Add(new Employee("Bruce", "Cambell", "Sales Manager", "Education includes a BA in psychology from Colorado State University in 1970. He also completed 'The Art of the Cold Call.' Bruce is a member of Toastmasters International."));
employees[0].Orders.Add(new Order("Suppliers Inc.", DateTime.Now, "TV", 20));
employees[0].Orders.Add(new Order("Suppliers Inc.", DateTime.Now.AddDays(3), "Projector", 15));
employees.Add(new Employee("Cindy", "Haneline", "Vice President of Sales", "Cindy received her BTS commercial in 1974 and a Ph.D. in international marketing from the University of Dallas in 1981. She is fluent in French and Italian and reads German. She joined the company as a sales representative, was promoted to sales manager in January 1992 and to vice president of sales in March 1993. Cindy is a member of the Sales Management Roundtable, the Seattle Chamber of Commerce, and the Pacific Rim Importers Association."));
employees[1].Orders.Add(new Order("Suppliers Inc.", DateTime.Now.AddDays(1), "Blu-Ray Player", 10));
}
}
public class Employee
{
private string firstName;
private string lastName;
private string title;
private string notes;
private List<Order> orders;
public Employee(string firstName, string lastName, string title, string notes)
{
this.firstName = firstName;
this.lastName = lastName;
this.title = title;
this.notes = notes;
this.orders = new List<Order>();
}
public Employee() { }
public string FirstName { get { return firstName; } set { firstName = value; } }
public string LastName { get { return lastName; } set { lastName = value; } }
public string Title { get { return title; } set { title = value; } }
public string Notes { get { return notes; } set { notes = value; } }
public List<Order> Orders { get { return orders; } }
}
public class Order
{
private string supplier;
private DateTime date;
private string productName;
private int quantity;
public Order(string supplier, DateTime date, string productName, int quantity)
{
this.supplier = supplier;
this.date = date;
this.productName = productName;
this.quantity = quantity;
}
public string Supplier { get { return supplier; } set { supplier = value; } }
public DateTime Date { get { return date; } set { date = value; } }
public string ProductName { get { return productName; } set { productName = value; } }
public int Quantity { get { return quantity; } set { quantity = value; } }
}
}
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Navigation
Imports System.Windows.Shapes
Imports DevExpress.Xpf.Grid
Namespace WpfApplication18
''' <summary>
''' Interaction logic for MainWindow.xaml
''' </summary>
Partial Public Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
gridControl1.ItemsSource = Employees
End Sub
#Region "#GridInCode"
Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim newGrid As GridControl = CreateGrid()
AddDetailsToGrid(newGrid)
Grid.SetRow(newGrid, 2)
mainGrid.Children.Add(newGrid)
End Sub
Private Function CreateGrid() As GridControl
Dim newGrid As New GridControl()
newGrid.AutoGenerateColumns = AutoGenerateColumnsMode.AddNew
newGrid.View = New TableView()
TryCast(newGrid.View, TableView).AutoWidth = True
TryCast(newGrid.View, TableView).ShowGroupPanel = False
newGrid.View.DetailHeaderContent = "Employees"
newGrid.ItemsSource = Employees
Return newGrid
End Function
Private Sub AddDetailsToGrid(ByVal grid As GridControl)
Dim dataControlDetail As New DataControlDetailDescriptor()
dataControlDetail.ItemsSourcePath = "Orders"
Dim detailGrid As New GridControl()
dataControlDetail.DataControl = detailGrid
detailGrid.AutoGenerateColumns = AutoGenerateColumnsMode.AddNew
detailGrid.View.DetailHeaderContent = "Orders"
TryCast(detailGrid.View, TableView).ShowGroupPanel = False
Dim contentDetail As New ContentDetailDescriptor()
'contentDetail.ContentTemplate = CType(FindResource("EmployeeNotes"), DataTemplate)
Dim dt As New DataTemplate()
Dim txFactory As New FrameworkElementFactory(GetType(TextBox))
txFactory.SetValue(TextBox.TextWrappingProperty, TextWrapping.Wrap)
txFactory.SetBinding(TextBox.TextProperty, New Binding("Notes"))
dt.VisualTree = txFactory
contentDetail.ContentTemplate = dt
contentDetail.HeaderContent = "Notes"
'Dim tabDetail As New TabViewDetailDescriptor()
'tabDetail.DetailDescriptors.Add(dataControlDetail)
'tabDetail.DetailDescriptors.Add(contentDetail)
grid.DetailDescriptor = contentDetail
End Sub
#End Region ' #GridInCode
Private employees_Renamed As List(Of Employee)
Private ReadOnly Property Employees() As List(Of Employee)
Get
If employees_Renamed Is Nothing Then
PopulateEmployees()
End If
Return employees_Renamed
End Get
End Property
Private Sub PopulateEmployees()
employees_Renamed = New List(Of Employee)()
employees_Renamed.Add(New Employee("Bruce", "Cambell", "Sales Manager", "Education includes a BA in psychology from Colorado State University in 1970. He also completed 'The Art of the Cold Call.' Bruce is a member of Toastmasters International."))
employees_Renamed(0).Orders.Add(New Order("Suppliers Inc.", DateTime.Now, "TV", 20))
employees_Renamed(0).Orders.Add(New Order("Suppliers Inc.", DateTime.Now.AddDays(3), "Projector", 15))
employees_Renamed.Add(New Employee("Cindy", "Haneline", "Vice President of Sales", "Cindy received her BTS commercial in 1974 and a Ph.D. in international marketing from the University of Dallas in 1981. She is fluent in French and Italian and reads German. She joined the company as a sales representative, was promoted to sales manager in January 1992 and to vice president of sales in March 1993. Cindy is a member of the Sales Management Roundtable, the Seattle Chamber of Commerce, and the Pacific Rim Importers Association."))
employees_Renamed(1).Orders.Add(New Order("Suppliers Inc.", DateTime.Now.AddDays(1), "Blu-Ray Player", 10))
End Sub
End Class
Public Class Employee
Private firstName_Renamed As String
Private lastName_Renamed As String
Private title_Renamed As String
Private notes_Renamed As String
Private orders_Renamed As List(Of Order)
Public Sub New(ByVal firstName As String, ByVal lastName As String, ByVal title As String, ByVal notes As String)
Me.firstName_Renamed = firstName
Me.lastName_Renamed = lastName
Me.title_Renamed = title
Me.notes_Renamed = notes
Me.orders_Renamed = New List(Of Order)()
End Sub
Public Sub New()
End Sub
Public Property FirstName() As String
Get
Return firstName_Renamed
End Get
Set(ByVal value As String)
firstName_Renamed = value
End Set
End Property
Public Property LastName() As String
Get
Return lastName_Renamed
End Get
Set(ByVal value As String)
lastName_Renamed = value
End Set
End Property
Public Property Title() As String
Get
Return title_Renamed
End Get
Set(ByVal value As String)
title_Renamed = value
End Set
End Property
Public Property Notes() As String
Get
Return notes_Renamed
End Get
Set(ByVal value As String)
notes_Renamed = value
End Set
End Property
Public ReadOnly Property Orders() As List(Of Order)
Get
Return orders_Renamed
End Get
End Property
End Class
Public Class Order
Private supplier_Renamed As String
Private date_Renamed As DateTime
Private productName_Renamed As String
Private quantity_Renamed As Integer
Public Sub New(ByVal supplier As String, ByVal [date] As DateTime, ByVal productName As String, ByVal quantity As Integer)
Me.supplier_Renamed = supplier
Me.date_Renamed = [date]
Me.productName_Renamed = productName
Me.quantity_Renamed = quantity
End Sub
Public Property Supplier() As String
Get
Return supplier_Renamed
End Get
Set(ByVal value As String)
supplier_Renamed = value
End Set
End Property
Public Property [Date]() As DateTime
Get
Return date_Renamed
End Get
Set(ByVal value As DateTime)
date_Renamed = value
End Set
End Property
Public Property ProductName() As String
Get
Return productName_Renamed
End Get
Set(ByVal value As String)
productName_Renamed = value
End Set
End Property
Public Property Quantity() As Integer
Get
Return quantity_Renamed
End Get
Set(ByVal value As Integer)
quantity_Renamed = value
End Set
End Property
End Class
End Namespace