翻譯|使用教程|編輯:龔雪|2025-10-30 10:24:09.123|閱讀 46 次
概述:本文主要介紹如何在MVVM應用程序中使用虛擬源,歡迎下載最新版組件體驗!
#慧都22周年慶大促·界面/圖表報表/文檔/IDE/IOT/測試等千款熱門軟控件火熱促銷中>>
相關鏈接:
DevExpress WPF擁有120+個控件和庫,將幫助您交付滿足甚至超出企業需求的高性能業務應用程序。通過DevExpress WPF能創建有著強大互動功能的XAML基礎應用程序,這些應用程序專注于當代客戶的需求和構建未來新一代支持觸摸的解決方案。 無論是Office辦公軟件的衍伸產品,還是以數據為中心的商業智能產品,都能通過DevExpress WPF控件來實現。
本文將為大家一步一步演示如何在一個MVVM應用程序中使用虛擬源。
注意:本教程使用作為示例數據源,使用作為虛擬數據源。
DevExpress技術交流群12:1028386091 歡迎一起進群討論
您可以顯示關于行組或單個數據列的摘要信息,完成以下步驟:
1. 在虛擬源中處理摘要。
2. 在GridControl中顯示摘要。
允許您獲得:
C#
public class IssuesSummaries {
public int Count { get; private set; }
public DateTime? LastCreated { get; private set; }
}
在虛擬源中處理摘要
1. 創建一個使用IssuesService.GetSummariesAsync方法從數據源獲取摘要的任務。
2. 使用屬性獲取GridControl摘要項。
3. 創建GetTotalSummaries命令。
4. 獲取與GridControl摘要項對應的數據源摘要列表,并將該列表分配給屬性。
5. 將GetTotalSummaries命令綁定到。
C#
[Command]
public void GetTotalSummaries(GetSummariesAsyncArgs args) {
args.Result = GetTotalSummariesAsync(args);
}
static async Task<object[]> GetTotalSummariesAsync(GetSummariesAsyncArgs args) {
var summaryValues = await IssuesService.GetSummariesAsync((IssueFilter)args.Filter);
return args.Summaries.Select(x => {
if(x.SummaryType == SummaryType.Count)
return (object)summaryValues.Count;
if(x.SummaryType == SummaryType.Max && x.PropertyName == "Created")
return summaryValues.LastCreated;
throw new InvalidOperationException();
}).ToArray();
}
xml
<dxg:GridControl.ItemsSource>
<dx:InfiniteAsyncSource ElementType="{x:Type local:IssueData}"
FetchRowsCommand="{Binding FetchIssuesCommand}"
GetUniqueValuesCommand="{Binding GetUniqueValuesCommand}"
GetTotalSummariesCommand="{Binding GetTotalSummariesCommand}"/>
</dxg:GridControl.ItemsSource>
顯示固定摘要面板
啟用屬性來顯示固定摘要面板:
xml
<dxg:GridControl.View> <dxg:TableView ShowFixedTotalSummary="True"/> </dxg:GridControl.View>
顯示總摘要
指定屬性在GridControl中顯示總的摘要:
xml
<dxg:GridControl.TotalSummary>
<dxg:GridSummaryItem SummaryType="Count" Alignment="Right"/>
<dxg:GridSummaryItem SummaryType="Max" FieldName="Created"
DisplayFormat="{}Last created: {0}"
Alignment="Right"/>
</dxg:GridControl.TotalSummary>
可以計算Median和StdDev值:
C#
public class IssuesSummaries {
// ...
public double VotesMedian { get; private set; }
public double VotesStdDev { get; private set; }
}
1. 在虛擬源中的過程摘要:
C#
[Command]
public void GetTotalSummaries(GetSummariesAsyncArgs args) {
args.Result = GetTotalSummariesAsync(args);
}
static async Task<object[]> GetTotalSummariesAsync(GetSummariesAsyncArgs args) {
var summaryValues = await IssuesService.GetSummariesAsync((IssueFilter)args.Filter);
return args.Summaries.Select(x => {
if (x.SummaryType == SummaryType.Count)
return (object)summaryValues.Count;
if (x.SummaryType == SummaryType.Max && x.PropertyName == "Created")
return summaryValues.LastCreated;
// Custom Summaries
if (x.SummaryType == SummaryType.Custom && x.PropertyName == "Votes") {
var tag = x.Tag as string;
if (tag == "Median")
return summaryValues.VotesMedian;
if (tag == "StdDev")
return summaryValues.VotesStdDev;
}
throw new InvalidOperationException();
}).ToArray();
}
2. 在GridControl中顯示摘要:
xml
<dxg:GridControl.TotalSummary>
<dxg:GridSummaryItem SummaryType="Count" Alignment="Right"/>
<dxg:GridSummaryItem SummaryType="Max" FieldName="Created"
DisplayFormat="{}Last created: {0}" Alignment="Right"/>
<!-- Custom Summaries -->
<dxg:GridSummaryItem SummaryType="Custom" Tag="StdDev" FieldName="Votes"
DisplayFormat="{}Votes StdDev={0}" Alignment="Right"/>
<dxg:GridSummaryItem SummaryType="Custom" Tag="Median" FieldName="Votes"
DisplayFormat="{}Votes Median={0}" Alignment="Right"/>
</dxg:GridControl.TotalSummary>
更多產品資訊及授權,歡迎來電咨詢:023-68661681
慧都是?家?業數字化解決?案公司,專注于軟件、?油與?業領域,以深?的業務理解和?業經驗,幫助企業實現智能化轉型與持續競爭優勢。
慧都是DevExpress的中國區的合作伙伴,DevExpress作為用戶界面領域的優秀產品,幫助企業高效構建權限管理、數據可視化(如網格/圖表/儀表盤)、跨平臺系統(WinForms/ASP.NET/.NET MAUI)及行業定制解決方案,加速開發并強化交互體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn
文章轉載自:慧都網