■ GridControl 클래스에서 커스텀 컬럼 선택자를 생성하는 방법을 보여준다.
▶ CustomColumnChooser.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
using System.Windows; using System.Windows.Controls; using DevExpress.Xpf.Core; namespace TestProject { /// <summary> /// 커스텀 컬럼 선택자 /// </summary> public class CustomColumnChooser : IColumnChooser, IColumnChooserFactory { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 커스텀 컬럼 선택자 컨트롤 /// </summary> private readonly CustomColumnChooserControl customColumnChooserControl; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public // IColumnChooser #region 상위 컨테이너 - TopContainer /// <summary> /// 상위 컨테이너 /// </summary> public UIElement TopContainer { get { return this.customColumnChooserControl.ColunmChooserControl; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - CustomColumnChooser(customColumnChooserControl) /// <summary> /// 생성자 /// </summary> /// <param name="customColumnChooserControl">커스텀 컬럼 선택자 컨트롤</param> public CustomColumnChooser(CustomColumnChooserControl customColumnChooserControl) { this.customColumnChooserControl = customColumnChooserControl; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method #region (IColumnChooserFactory) 보여주기 - Show() /// <summary> /// 보여주기 /// </summary> public void Show() { } #endregion #region (IColumnChooserFactory) 숨기기 - Hide() /// <summary> /// 숨기기 /// </summary> public void Hide() { } #endregion #region (IColumnChooserFactory) 상태 적용하기 - ApplyState(columnChooserState) /// <summary> /// 상태 적용하기 /// </summary> /// <param name="columnChooserState">컬럼 선택자 상태</param> public void ApplyState(IColumnChooserState columnChooserState) { } #endregion #region (IColumnChooserFactory) 상태 저장하기 - SaveState(columnChooserState) /// <summary> /// 상태 저장하기 /// </summary> /// <param name="columnChooserState">컬럼 선택자 상태</param> public void SaveState(IColumnChooserState columnChooserState) { } #endregion #region (IColumnChooserFactory) 파괴하기 - Destroy() /// <summary> /// 파괴하기 /// </summary> public void Destroy() { } #endregion #region (IColumnChooserFactory) 생성하기 - Create(ownerControl) /// <summary> /// 생성하기 /// </summary> /// <param name="ownerControl">오너 컨트롤</param> /// <returns>IColumnChooser 객체</returns> public IColumnChooser Create(Control ownerControl) { return this; } #endregion } } |
▶ CustomColumnChooserControl.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
using System.Windows; using System.Windows.Controls; using DevExpress.Xpf.Grid; namespace TestProject { /// <summary> /// 커스텀 컬럼 선택자 컨트롤 /// </summary> public class CustomColumnChooserControl : Control { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Field #region Field /// <summary> /// 뷰 속성 /// </summary> public static readonly DependencyProperty ViewProperty = DependencyProperty.Register("View", typeof(GridViewBase), typeof(CustomColumnChooserControl), new UIPropertyMetadata(null)); #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Internal #region 컬럼 선택자 컨트롤 - ColunmChooserControl /// <summary> /// 컬럼 선택자 컨트롤 /// </summary> internal ColumnChooserControl ColunmChooserControl { get; private set; } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Public #region 뷰 - View /// <summary> /// 뷰 /// </summary> public GridViewBase View { get { return (GridViewBase)GetValue(ViewProperty); } set { SetValue(ViewProperty, value); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - CustomColumnChooserControl() /// <summary> /// 생성자 /// </summary> public CustomColumnChooserControl() { DefaultStyleKey = typeof(CustomColumnChooserControl); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 템플리트 적용시 처리하기 - OnApplyTemplate() /// <summary> /// 템플리트 적용시 처리하기 /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); ColunmChooserControl = (ColumnChooserControl)GetTemplateChild("PART_ColumnChooserControl"); } #endregion } } |
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" xmlns:local="clr-namespace:TestProject" Width="800" Height="600" Title="GridControl 클래스 : 커스텀 컬럼 선택자 생성하기" FontFamily="나눔고딕코딩" FontSize="16"> <Window.Resources> <Style TargetType="{x:Type local:CustomColumnChooserControl}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:CustomColumnChooserControl}"> <Expander x:Name="expander" Margin="5" IsExpanded="{Binding ElementName=PART_ColumnChooserControl, Path=Owner.IsColumnChooserVisible}"> <ContentControl> <Border CornerRadius="3" Padding="1" Background="LightGray"> <dx:NonLogicalDecorator> <dxg:ColumnChooserControl x:Name="PART_ColumnChooserControl" Owner="{TemplateBinding View}" Columns="{Binding Path=Owner.ColumnChooserColumns, RelativeSource={RelativeSource Self}}" /> </dx:NonLogicalDecorator> </Border> </ContentControl> </Expander> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Grid Margin="5"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="150" /> </Grid.ColumnDefinitions> <dxg:GridControl x:Name="gridControl"> <dxg:GridControl.Columns> <dxg:GridColumn FieldName="IssueName" /> <dxg:GridColumn FieldName="IssueType" Visible="False" /> <dxg:GridColumn FieldName="IsPrivate" Visible="False" /> </dxg:GridControl.Columns> <dxg:GridControl.View> <dxg:TableView x:Name="tableView" /> </dxg:GridControl.View> </dxg:GridControl> <local:CustomColumnChooserControl x:Name="customColumnChooserControl" Grid.Column="1" Margin="10" /> </Grid> </Window> |
▶ MainWindow.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
using System.Windows; using DevExpress.Xpf.Grid; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); this.gridControl.ItemsSource = new IssueList().GetData(); InitializeCustomColumnChooserControl(this.tableView); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 커스텀 컬럼 선택자 컨트롤 초기화 하기 - InitializeCustomColumnChooserControl(gridViewBase) /// <summary> /// 커스텀 컬럼 선택자 컨트롤 초기화 하기 /// </summary> /// <param name="gridViewBase">GridViewBase 객체</param> private void InitializeCustomColumnChooserControl(GridViewBase gridViewBase) { customColumnChooserControl.View = gridViewBase; gridViewBase.ColumnChooserFactory = new CustomColumnChooser(customColumnChooserControl); gridViewBase.ShowColumnChooser(); } #endregion } } |