■ TableView 클래스에서 데이터 주석 어트리뷰트를 사용해 검증하는 방법을 보여준다.
▶ Employee.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 |
using System.ComponentModel.DataAnnotations; namespace TestProject { /// <summary> /// 직원 /// </summary> public class Employee { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public int ID { get; set; } #endregion #region 상급자 ID - ParentID /// <summary> /// 상급자 ID /// </summary> public int ParentID { get; set; } #endregion #region 성명 - Name /// <summary> /// 성명 /// </summary> [Required(AllowEmptyStrings = false, ErrorMessage = "The Name cannot be empty. Please correct.")] public string Name { get; set; } #endregion #region 직위 - Position /// <summary> /// 직위 /// </summary> [StringLength(20)] public string Position { get; set; } #endregion #region 부서 - Department /// <summary> /// 부서 /// </summary> [Required(AllowEmptyStrings = false, ErrorMessage = "The Department cannot be empty. Please correct.")] public string Department { get; set; } #endregion } } |
▶ MainPage.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 |
<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" Width="600" Height="450" Title="TableView 클래스 : 데이터 주석 어트리뷰트를 사용해 검증하기"> <Grid> <dxg:GridControl Name="gridControl" > <dxg:GridControl.Columns> <dxg:GridColumn FieldName="Name" /> <dxg:GridColumn FieldName="Position" /> <dxg:GridColumn FieldName="Department" /> </dxg:GridControl.Columns> <dxg:GridControl.View> <dxg:TableView Name="tableView" ShowValidationAttributeErrors="True" AllowCommitOnValidationAttributeError="False" /> </dxg:GridControl.View> </dxg:GridControl> </Grid> </Window> |