DevExpress v20.1フルバージョンをダウンロードDevExpress v20.1 中国語リソース獲得
DevExpress Technical Exchange Group 2:775869749グループディスカッションへようこそ
DevExpress社のWPFコントロール、あなたは現代的な顧客のニーズに焦点を当て、強力なインタラクティブ機能を備えたXAMLベースのアプリケーションを作成することができますし、将来的にはタッチ対応ソリューションの新世代を構築します。
システムの背景
- プラットフォーム:WPF
- 製品:DXGrid for WPF
この記事では、DXGridでWcfInstantFeedbackDataSourceまたはWcfServerModeDataSourceを使用する方法と、特別な動作を通じてアプリケーションでCRUD操作(たとえば、追加、削除、編集)を実装する方法を示します。
このテストでは、SQL Expressサービスがコンピューターにインストールされている必要があります。
次の例のように、GridControlのWCFServerModeCRUDBehaviorおよびWCFInstantModeCRUDBehavior追加操作を作成しました。
<DXG:GRIDCONTROL> <I:Interaction.Behaviors> <CRUD:WCFServerModeCRUDBehavior ...> <CRUD:WCFServerModeCRUDBehavior.DataSource /> <dxsm:LinqServerModeDataSource ... /> </crud:WCFServerModeCRUDBehavior.DataSource> </ CRUD:WCFServerModeCRUDBehavior > </i:Interaction.Behaviors> </ dxg:GridControl>
WCFServerModeCRUDBehaviorクラスとWCFInstantModeCRUDBehaviorクラスには、「行の追加」および「行の編集」操作を提供する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 "/>TextEdit x:Name = "txtCompany" Grid.Row = "1" Grid.Column = "1" EditValue = "{Binding Path = Name、Mode = TwoWay}" Margin = "0,0,0,4" /> < / Grid> </ StackPanel> <TextBlock Text = "Name:" 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" /> </ DataTemplate> <crud:WCFServerModeCRUDBehavior NewRowForm = "{StaticResource ResourceKey = EditRecordTemplate}" EditRowForm = "{StaticResource ResourceKey = EditRecordTemplate}" />
このアクションクラスには、データモデルに次の情報が必要です。
- EntityObjectType-行のタイプ。
- DataServiceContext-DataServiceContextタイプのオブジェクト。
- PropertiesList-テーブル列のリスト。
- PrimaryKey-データベーステーブルの主キー。
- タイプWcfInstantFeedbackDataSourceまたはWcfServerModeDataSourceのDataSource-Object。
<dxg:GridControl> <i:Interaction.Behaviors> <crud:WCFInstantModeCRUDBehavior EntityObjectType = "{x:Type sr:Item}" DataSource = "{Binding ElementName = wcfInstantSource}" DataServiceContext = "{Binding DataSource.DataServiceContext、RelativeSource = { RelativeSource Self}} "/> </i:Interaction.Behaviors> </ dxg:GridControl>
helper.PropertiesList.Add( "Id"); helper.PropertiesList.Add( "Name");
WcfInstantFeedbackDataSourceおよびWcfServerModeDataSourceの詳細については、WcfInstantFeedbackDataSourceおよびWcfServerModeDataSourceクラスを参照してください。
操作クラスの子孫は、次のコマンドをサポートします:NewRowCommand、RemoveRowCommand、EditRowCommandこれらのコマンドでインタラクティブなコントロールを簡単にバインドできます。例えば:
<crud:WCFServerModeCRUDBehavior 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>
既定では、WCFServerModeCRUDBehaviorおよびWCFInstantModeCRUDBehaviorソリューションは、次のエンドユーザー操作機能をサポートしています。
- エンドユーザーは、グリッド行をダブルクリックするか、AllowKeyDownActionsプロパティがTrueのときにEnterキーを押すことにより、選択した行の値を編集できます。
- AllowKeyDownActionsプロパティがTrueの場合、エンドユーザーはDeleteキーを使用して選択した行を削除できます。
- エンドユーザーは、NewRowCommand、RemoveRowCommand、およびEditRowCommandコマンドを使用して、新しい行を追加、削除、および編集できます。