작업 3: 도구 상자 및 PropertyGrid 창 만들기
이 작업에서는 도구 상자 및 PropertyGrid 창을 만든 후 다시 호스트된 Windows 워크플로 디자이너에 추가합니다.
일련의 워크플로 디자이너 재호스트 항목에 있는 세 가지 작업을 완료한 후 MainWindow.xaml.cs 파일에 포함되는 코드가 이 항목의 마지막에 참조용으로 제공됩니다.
도구 상자를 만들어 표에 추가하려면
작업 2: 워크플로 디자이너 호스트에 설명되어 있는 절차를 수행하여 결과로 얻은 HostingApplication 프로젝트를 엽니다.
솔루션 탐색기 창에서 MainWindow.xaml 파일을 마우스 오른쪽 단추로 클릭하고 코드 보기를 선택합니다.
MainWindow
클래스에GetToolboxControl
메서드를 추가합니다. 이 메서드는 ToolboxControl을 만들고 새 도구 상자 범주를 도구 상자에 추가하며 Assign 및 Sequence 활동 형식을 해당 범주에 할당합니다.private ToolboxControl GetToolboxControl() { // Create the ToolBoxControl. var ctrl = new ToolboxControl(); // Create a category. var category = new ToolboxCategory("category1"); // Create Toolbox items. var tool1 = new ToolboxItemWrapper("System.Activities.Statements.Assign", typeof(Assign).Assembly.FullName, null, "Assign"); var tool2 = new ToolboxItemWrapper("System.Activities.Statements.Sequence", typeof(Sequence).Assembly.FullName, null, "Sequence"); // Add the Toolbox items to the category. category.Add(tool1); category.Add(tool2); // Add the category to the ToolBox control. ctrl.Categories.Add(category); return ctrl; }
MainWindow
클래스에 프라이빗AddToolbox
메서드를 추가합니다. 이 메서드는 표의 왼쪽 열에 도구 상자를 배치합니다.private void AddToolBox() { ToolboxControl tc = GetToolboxControl(); Grid.SetColumn(tc, 0); grid1.Children.Add(tc); }
다음 코드와 같이
MainWindow()
클래스 생성자에AddToolBox
메서드에 대한 호출을 추가합니다.public MainWindow() { InitializeComponent(); this.RegisterMetadata(); this.AddDesigner(); this.AddToolBox(); }
F5 키를 눌러 솔루션을 빌드하고 실행합니다. Assign 및 Sequence 활동이 포함된 도구 상자가 표시됩니다.
PropertyGrid를 만들려면
솔루션 탐색기 창에서 MainWindow.xaml 파일을 마우스 오른쪽 단추로 클릭하고 코드 보기를 선택합니다.
MainWindow
클래스에AddPropertyInspector
메서드를 추가하여 표의 맨 오른쪽 열에 PropertyGrid 창을 배치합니다.private void AddPropertyInspector() { Grid.SetColumn(wd.PropertyInspectorView, 2); grid1.Children.Add(wd.PropertyInspectorView); }
다음 코드와 같이
MainWindow()
클래스 생성자에AddPropertyInspector
메서드에 대한 호출을 추가합니다.public MainWindow() { InitializeComponent(); this.RegisterMetadata(); this.AddDesigner(); this.AddToolBox(); this.AddPropertyInspector(); }
F5 키를 눌러 솔루션을 빌드하고 실행합니다. 도구 상자, 워크플로 디자인 캔버스 및 PropertyGrid 창이 모두 표시됩니다. Assign 활동 또는 Sequence 활동을 디자인 캔버스로 끌면 강조 표시된 활동에 따라 속성 표가 업데이트됩니다.
예제
이제 MainWindow.xaml.cs 파일에 다음 코드가 들어 있어야 합니다.
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;
// dlls added.
using System.Activities;
using System.Activities.Core.Presentation;
using System.Activities.Presentation;
using System.Activities.Presentation.Metadata;
using System.Activities.Presentation.Toolbox;
using System.Activities.Statements;
using System.ComponentModel;
namespace HostingApplication
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private WorkflowDesigner wd;
public MainWindow()
{
InitializeComponent();
RegisterMetadata();
AddDesigner();
this.AddToolBox();
this.AddPropertyInspector();
}
private void AddDesigner()
{
// Create an instance of WorkflowDesigner class.
this.wd = new WorkflowDesigner();
// Place the designer canvas in the middle column of the grid.
Grid.SetColumn(this.wd.View, 1);
// Load a new Sequence as default.
this.wd.Load(new Sequence());
// Add the designer canvas to the grid.
grid1.Children.Add(this.wd.View);
}
private void RegisterMetadata()
{
var dm = new DesignerMetadata();
dm.Register();
}
private ToolboxControl GetToolboxControl()
{
// Create the ToolBoxControl.
var ctrl = new ToolboxControl();
// Create a category.
var category = new ToolboxCategory("category1");
// Create Toolbox items.
var tool1 =
new ToolboxItemWrapper("System.Activities.Statements.Assign",
typeof(Assign).Assembly.FullName, null, "Assign");
var tool2 = new ToolboxItemWrapper("System.Activities.Statements.Sequence",
typeof(Sequence).Assembly.FullName, null, "Sequence");
// Add the Toolbox items to the category.
category.Add(tool1);
category.Add(tool2);
// Add the category to the ToolBox control.
ctrl.Categories.Add(category);
return ctrl;
}
private void AddToolBox()
{
ToolboxControl tc = GetToolboxControl();
Grid.SetColumn(tc, 0);
grid1.Children.Add(tc);
}
private void AddPropertyInspector()
{
Grid.SetColumn(wd.PropertyInspectorView, 2);
grid1.Children.Add(wd.PropertyInspectorView);
}
}
}
참고 항목
.NET