WPF 인터페이스 개발이 너무 어렵습니까? DevExpress는 CRUD 처리 방법을 알려줍니다.

DevExpress Technical Exchange Group 2 : 775869749 그룹 토론에 오신 것을 환영합니다.

DevExpress v20.1 정식 버전 다운로드 DevExpress v20.1     중국어 리소스 획득

함께 DevExpress의 WPF 컨트롤 , 당신은 현대 고객의 요구에 초점을 강력한 대화 형 기능을 가진 XAML 기반 응용 프로그램을 만들 수 있습니다와 미래의 터치 지원 솔루션의 새로운 세대를 구축 할 수 있습니다.

시스템 배경

  • 플랫폼 : WPF
  • 제품 : WPF 용 DXGrid

이 기사에서는 DXGrid와 함께 LinqInstantFeedbackDataSource 또는 LinqServerModeDataSource를 사용하는 방법과 특수 동작을 통해 애플리케이션에서 CRUD 작업 (예 : 추가, 삭제, 편집)을 구현하는 방법을 보여줍니다.

이 테스트 샘플을 사용하려면 컴퓨터에 SQL Express 서비스가 설치되어 있어야합니다.

GridControl에 대한 LINQServerModeCRUDBehavior 및 LINQInstantModeCRUDBehavior 추가 작업을 만듭니다. 예를 들면 다음과 같습니다.

 

<dxg : GridControl> 

<dxmvvm : Interaction.Behaviors> 

<crud : LINQServerModeCRUDBehavior ...> 

<crud : LINQServerModeCRUDBehavior.DataSource /> 

<dxsm : LinqServerModeDataSource ... /> 

</crud:LINQServerModeCRUDBehavior.DataSource> 

</ crud : LINQServerModeCRUDBehavior > 

</dxmvvm:Interaction.Behaviors> 

</ dxg : GridControl>

 

LINQServerModeCRUDBehavior 및 LINQInstantModeCRUDBehavior 클래스에는 "행 추가"및 "행 편집"작업을 제공하는 NewRowForm 및 EditRowForm 속성이 포함되어 있습니다. 이러한 속성을 사용하여 필요에 따라 추가 및 편집 양식을 만들 수 있습니다.

 

<DataTemplate x : Key = "EditRecordTemplate"> 

<StackPanel Margin = "8"MinWidth = "200"> 

<Grid> 

<Grid.ColumnDefinitions> 

<ColumnDefinition /> 

<ColumnDefinition /> 

</Grid.ColumnDefinitions> 

<Grid.RowDefinitions> 

<RowDefinition /> 

<RowDefinition /> 

</Grid.RowDefinitions> 

<TextBlock Text = "ID :"VerticalAlignment = "Center"Grid.Row = "0"Grid.Column = "0"Margin = "0,0,6, 4 "/> 

<dxe : TextEdit x : Name ="txtID "Grid.Row ="0 "Grid.Column ="1 "EditValue ="{Binding Path = Id, Mode = TwoWay} "Margin ="0,0, 0,4 "/> 

<TextBlock Text = "이름 :"VerticalAlignment = "Center"Grid.Row = "1"Grid.Column = "0"Margin = "0,0,6,4"/>

<dxe : TextEdit x : Name = "txtCompany"Grid.Row = "1"Grid.Column = "1"EditValue = "{Binding Path = Name, Mode = TwoWay}"Margin = "0,0,0,4" /> 

</ Grid> 

</ StackPanel> 

</ DataTemplate> 

<crud : LINQServerModeCRUDBehavior NewRowForm = "{StaticResource ResourceKey = EditRecordTemplate}"EditRowForm = "{StaticResource ResourceKey = EditRecordTemplate}"/>

 

이러한 작업 클래스에는 데이터 모델에 다음 정보가 필요합니다.

  • RowType- 행의 유형.
  • DataContext- 데이터베이스 엔티티;
  • DataSource-LinqInstantFeedbackDataSource 또는 LinqServerModeDataSource 유형 객체.

 

<dxg : GridControl> 

<i : Interaction.Behaviors> 

<crud : LINQServerModeCRUDBehavior RowType = "{x : Type local : Item}"DataContext = "{Binding Source = {StaticResource DataClassesDataContext}}"> 

<crud : LINQServerModeCRUDBehavior.DataSource> 

< dxsm : LinqServerModeDataSource KeyExpression = "Id"QueryableSource = "{Binding Items, Source = {StaticResource DataClassesDataContext}}"/> 

</crud:LINQServerModeCRUDBehavior.DataSource> 

</ crud : LINQServerModeCRUDBehavior> 

</i:Interaction.Behaviors> 

</ dxg : GridControl>

 

LinqServerModeDataSourceLinqInstantFeedbackDataSource 에 대한 자세한 내용은 LinqServerModeDataSource 및 LinqInstantFeedbackDataSource 클래스를 참조하십시오  .

작업 클래스의 하위 항목은 NewRowCommand, RemoveRowCommand, EditRowCommand 명령을 지원합니다. 예를 들어 대화 형 컨트롤을 이러한 명령에 쉽게 바인딩 할 수 있습니다.

 

<crud : LINQServerModeCRUDBehavior x : Name = "helper"/> 

<StackPanel Grid.Row = "1"Orientation = "Horizontal"HorizontalAlignment = "Center"> 

<Button Height = "22"Width = "60"Command = "{Binding Path = NewRowCommand, ElementName = helper} "> 추가 </ Button> 

<Button Height ="22 "Width ="60 "Command ="{Binding Path = RemoveRowCommand, ElementName = helper} "Margin ="6,0,6, 0 "> 제거 </ Button> 

<Button Height ="22 "Width ="60 "Command ="{Binding Path = EditRowCommand, ElementName = helper} "> 편집 </ Button> 

</ StackPanel>

 

기본적으로 LINQServerModeCRUDBehavior 및 LINQInstantModeCRUDBehavior 솔루션은 다음과 같은 최종 사용자 상호 작용 기능을 지원합니다.

  1. 최종 사용자는 그리드 행을 두 번 클릭하거나 AllowKeyDownActions 속성이 True 일 때 Enter 키를 눌러 선택한 행 값을 편집 할 수 있습니다.
  2. AllowKeyDownActions 속성이 True이면 최종 사용자는 Delete 키를 통해 선택한 행을 삭제할 수 있습니다.
  3. 최종 사용자는 NewRowCommand, RemoveRowCommand 및 EditRowCommand 명령을 통해 새 행을 추가, 삭제 및 편집 할 수 있습니다.

DevExpress 중국어 웹 사이트에서 직접 DevExpress 상담을 받으십시오!

추천

출처blog.csdn.net/AABBbaby/article/details/108639159