■ GridControl 클래스에서 커스텀 필터 드롭 다운을 생성하는 방법을 보여준다.
▶ IntegerToBinaryOperatorValueConverter.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 |
using System; using System.Globalization; using System.Windows.Data; using DevExpress.Data.Filtering; namespace TestProject { /// <summary> /// 정수↔바이너리 연산자 값 변환자 /// </summary> public class IntegerToBinaryOperatorValueConverter : IValueConverter { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 변환하기 - Convert(value, targetType, parameter, cultureInfo) /// <summary> /// 변환하기 /// </summary> /// <param name="value">값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">CultureInfo 객체</param> /// <returns>변환 값</returns> public object Convert(object value, Type targetType, object parameter, CultureInfo cultureInfo) { BinaryOperator binaryOperator = value as BinaryOperator; if(object.ReferenceEquals(binaryOperator, null)) { return null; } OperandValue operandValue = binaryOperator.RightOperand as OperandValue; return operandValue.Value; } #endregion #region 역변환하기 - ConvertBack(value, targetType, parameter, cultureInfo) /// <summary> /// 역변환하기 /// </summary> /// <param name="value">값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">CultureInfo 객체</param> /// <returns>역변환 값</returns> public object ConvertBack(object value, Type targetType, object parameter, CultureInfo cultureInfo) { return new BinaryOperator("Index", System.Convert.ToInt32(value), BinaryOperatorType.Greater); } #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 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" xmlns:local="clr-namespace:TestProject" Width="800" Height="600" Title="커스텀 필터 드롭 다운 생성하기" FontFamily="나눔고딕코딩" FontSize="16"> <Grid> <Grid.Resources> <local:IntegerToBinaryOperatorValueConverter x:Key="IntegerToBinaryOperatorValueConverterKey" /> </Grid.Resources> <dxg:GridControl x:Name="gridControl"> <dxg:GridControl.Columns> <dxg:GridColumn FieldName="Index" FilterPopupMode="Custom"> <dxg:GridColumn.CustomColumnFilterPopupTemplate> <DataTemplate> <StackPanel> <Label Margin="5" Content="Minimum Index :" /> <Slider Margin="5" Width="200" Minimum="1" Maximum="99" Value="{Binding Path=CustomColumnFilter, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource IntegerToBinaryOperatorValueConverterKey}}" /> </StackPanel> </DataTemplate> </dxg:GridColumn.CustomColumnFilterPopupTemplate> </dxg:GridColumn> </dxg:GridControl.Columns> <dxg:GridControl.View> <dxg:TableView /> </dxg:GridControl.View> </dxg:GridControl> </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 |
using System.Windows; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); this.gridControl.ItemsSource = new SampleList().GetData(); } #endregion } } |