溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Dev WPF界面開發(fā)中如何實(shí)現(xiàn)操作

發(fā)布時(shí)間:2021-11-15 15:58:26 來源:億速云 閱讀:179 作者:柒染 欄目:大數(shù)據(jù)

Dev WPF界面開發(fā)中如何實(shí)現(xiàn)操作,針對(duì)這個(gè)問題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡單易行的方法。

通過DevExpress WPF Controls,您能創(chuàng)建有著強(qiáng)大互動(dòng)功能的XAML基礎(chǔ)應(yīng)用程序,這些應(yīng)用程序?qū)W⒂诋?dāng)代客戶的需求和構(gòu)建未來新一代支持觸摸的解決方案。

系統(tǒng)背景

  • 平臺(tái):WPF

  • 產(chǎn)品:DXGrid for WPF

本文將演示如何將WcfInstantFeedbackDataSource或WcfServerModeDataSource與DXGrid一起使用,以及如何通過特殊行為在應(yīng)用程序中實(shí)現(xiàn)CRUD操作(例如,添加、刪除、編輯)。

該測試需要在您的計(jì)算機(jī)上安裝SQL Express服務(wù)。

我們?yōu)镚ridControl創(chuàng)建了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屬性,以提供"Add Row"和"Edit Row"操作。使用這些屬性,可以根據(jù)需要?jiǎng)?chuàng)建添加和編輯表單:

<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="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" /> 
</Grid> 
</StackPanel> 
</DataTemplate> 
<crud:WCFServerModeCRUDBehavior NewRowForm="{StaticResource ResourceKey=EditRecordTemplate}" EditRowForm="{StaticResource ResourceKey=EditRecordTemplate}"/>

此操作類需要您的數(shù)據(jù)模型中的以下信息:

  • EntityObjectType - 行的類型;

  • DataServiceContext - DataServiceContext類型的對(duì)象;

  • PropertiesList - 表列的列表;

  • PrimaryKey - 數(shù)據(jù)庫表的主鍵;

  • DataSource - WcfInstantFeedbackDataSource或WcfServerModeDataSource類型的對(duì)象。

<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");

請(qǐng)參閱WcfInstantFeedbackDataSource和WcfServerModeDataSource類以了解有關(guān)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}">Add</Button> 
<Button Height="22" Width="60" Command="{Binding Path=RemoveRowCommand, ElementName=helper}" Margin="6,0,6,0">Remove</Button> 
<Button Height="22" Width="60" Command="{Binding Path=EditRowCommand, ElementName=helper}">Edit</Button> 
</StackPanel>

默認(rèn)情況下,WCFServerModeCRUDBehavior和WCFInstantModeCRUDBehavior解決方案支持以下最終用戶交互功能:

  1. 最終用戶可以通過雙擊網(wǎng)格行或在AllowKeyDownActions屬性為True的情況下按Enter鍵來編輯選定的行值。

  2. 如果AllowKeyDownActions屬性為True,則最終用戶可以通過Delete鍵刪除選定的行。

  3. 最終用戶可以通過NewRowCommand、RemoveRowCommand和EditRowCommand命令添加、刪除和編輯新行。

關(guān)于Dev WPF界面開發(fā)中如何實(shí)現(xiàn)操作問題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識(shí)。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI