最近使用wpf devexpress做一个wpf小项目,中间遇到了一些问题,这里记录下,同时也跟大家分享分享
1、devexpress安装
devexpress提供了很多控件,特别是各种形式的数据列表,做的又"花哨",性能又好,很让人羡慕。
我安装的是20.1.3.0版本,安装完成后,devexpress会在编译器中添加项目模板和文件模板(VS又慢了不少)、
生成Demo Center ,Demo Source Code,从创建项目到控件的使用和demo源代码的查看,一条龙服务。
一、devexpress基础控件
devexpress提供了很多控件和实例项目,刚接触的时候,让人眼花缭乱啊。建议在使用前,把他们运行起来都看一遍,
这样在使用的时候能大概知道使用哪种类型的控件更合适。
二、Devexpress MVVM
1、ViewModelBese:ViewModelBese继承了BindableBase,BindableBase实现了INotifyPropertyChanged接口。
自定义绑定属性最简单的写法:
public string UserName{ get { return GetValue<string>(); } set { SetValue(value); }}public ObservableCollection<ProductModel> ProductList{ get { return GetValue<ObservableCollection<ProductModel>>(); } set { SetValue(value); }}
2、POCO ViewModel
已经有了个ViewModelBese为什么还需要POCO ViewModel呢?
这里的POCO是:Plain Old CLR Objects,官方给的解释,主要作用是简化你的ViewModel
POCO (Plain Old CLR Objects) View Models simplify and speed up the development process.
POCO View Models allow you to:
Define bindable properties as simple auto-implemented properties.
Create methods that function as commands at runtime.
Make properties and methods implement MVVM-specific interfaces.
This allows you to create clean, simple, maintainable, and testable MVVM code.The POCO View Models are fully compatible with any WPF control.
You can use View Models Generated at Compile Time to generate boilerplate code for your ViewModels at compile time.
3、Messenger
跟MVVMlight的是Messenger使用差不多,但需要了解的是:
如果使用的是Messenger.Default.Register订阅消息,因为Messenger.Default是弱引用的信使,不会导致内存泄漏,因此不需要调用Messenger.Default.Unregister取消订阅
4、命令Commands
Xaml:
<Button Command="{Binding Path=TestCommand}" />
ViewModel:
public void Test(){}public bool CanTest(){}
5、异步命令Asynchronous Commands
Xaml:
<dxlc:LayoutControl Orientation="Vertical" VerticalAlignment="Top"><ProgressBar Minimum="0" Maximum="100" Value="{Binding Progress}" Height="20"/><Button Content="Calculate" Command="{Binding CalculateCommand}"/><Button Content="Cancel" Command="{Binding CalculateCommand.CancelCommand}"/></dxlc:LayoutControl>
ViewModel:
public AsyncCommand CalculateCommand { get; private set; }async Task Calculate() { for(int i = 0; i <= 100; i++) { if(CalculateCommand.IsCancellationRequested) { Progress = 0; return; } Progress = i; await Task.Delay(20); }}int _Progress;public int Progress{ get { return _Progress; } set { SetValue(ref _Progress, value); }}public AsyncDelegateCommandsViewModel() { CalculateCommand = new AsyncCommand(Calculate);}
6、消息框MessageBox
Xaml:
<dxmvvm:Interaction.Behaviors><dx:DXMessageBoxService x:Name="DXMessageBoxService" /></dxmvvm:Interaction.Behaviors>
ViewModel:
IMessageBoxService MessageBoxService{ get { return ServiceContainer.GetService<IMessageBoxService>(); }}
使用:
MessageBoxService.ShowMessage("xxx!", "提示", MessageButton.OK, MessageIcon.Information);
7、线程管理服务DispatcherService
Xaml:
<dxmvvm:Interaction.Behaviors><dxmvvm:DispatcherService /></dxmvvm:Interaction.Behaviors>
ViewModel:
IDispatcherService DispatcherService{ get { return this.GetService<IDispatcherService>(); }}//异步DispatcherService.BeginInvoke( async ()=>{ await Task.Delay(1000); ...});//同步DispatcherService.Invoke(new Action(()=> { ... }));
8、导出服务Export
Service:
IExportService CustomerExportService{ get { return GetService<IExportService>(); }}public interface IExportService{ void ExportToXls(string fileName);}public class ExportService : ServiceBase, IExportService{ public TableView View { get { return (TableView)GetValue(ViewProperty); } set { SetValue(ViewProperty, value); } } public static readonly DependencyProperty ViewProperty = DependencyProperty.Register("View", typeof(TableView), typeof(ExportService), new PropertyMetadata(null)); public void ExportToXls(string fileName) { if (View == null) return; View.ExportToXls(fileName); }}
Xaml:
<dxmvvm:Interaction.Behaviors> <services:ExportService View="{x:Reference View}" /></dxmvvm:Interaction.Behaviors><dxg:GridControl x:Name="GridControl" dx:ScrollBarExtensions.ScrollBarMode="TouchOverlap" AllowColumnMRUFilterList="False" AutoExpandAllGroups="True" DockPanel.Dock="Left" ItemsSource="{Binding Path=Customers}" SelectedItem="{Binding Path=SelectedCoustomer}" ShowBorder="False"><dxmvvm:Interaction.Behaviors> <dxmvvm:EventToCommand Command="{Binding UpdateCommand}" EventName="MouseDoubleClick" /> <dxmvvm:EventToCommand Command="{Binding SelectionChangedCommand}" EventName="SelectedItemChanged" /></dxmvvm:Interaction.Behaviors><dxg:GridControl.GroupSummary> <dxg:GridSummaryItem SummaryType="Count" /></dxg:GridControl.GroupSummary><dxg:GridControl.Columns> <dxg:GridColumn Width="1*" Binding="{Binding Path=AutoId}" FieldName="xxx" /> <dxg:GridColumn Width="3*" Binding="{Binding Path=IssueTime}" FieldName="日期"> <dxg:GridColumn.EditSettings> <dxe:DateEditSettings Mask="G" MaskUseAsDisplayFormat="True" /> </dxg:GridColumn.EditSettings> </dxg:GridColumn></dxg:GridControl.Columns><dxg:GridControl.TotalSummary> <dxg:GridSummaryItem Alignment="Right" SummaryType="Count" /> <dxg:GridSummaryItem FieldName="FullName" SummaryType="Count" /></dxg:GridControl.TotalSummary><dxg:GridControl.View><dxg:TableView x:Name="View" AllowBestFit="True" AllowCascadeUpdate="True" AllowDragDrop="False" AllowFixedGroups="True" AllowPrintColumnHeaderImage="True" AllowScrollAnimation="True" BestF......原文转载:http://www.shaoqun.com/a/851305.html
跨境电商:https://www.ikjzd.com/
阿里巴巴 批发:https://www.ikjzd.com/w/1084
asinseed:https://www.ikjzd.com/w/533
贝贝母婴网:https://www.ikjzd.com/w/1321
最近使用wpfdevexpress做一个wpf小项目,中间遇到了一些问题,这里记录下,同时也跟大家分享分享1、devexpress安装devexpress提供了很多控件,特别是各种形式的数据列表,做的又"花哨",性能又好,很让人羡慕。我安装的是20.1.3.0版本,安装完成后,devexpress会在编译器中添加项目模板和文件模板(VS又慢了不少)、生成DemoCenter,DemoSourceC
cima是什么:https://www.ikjzd.com/w/1372
日韩贸易战进入第十天,目前再次升级已趋失控!:https://www.ikjzd.com/articles/100994
亚马逊FBA卖家如何提高利润?先用这5种方式降低成本!:https://www.ikjzd.com/articles/100996
产品被亚马逊"二次"销售,Listing 惨遭下架!:https://www.ikjzd.com/articles/100997
速卖通货物纠纷的解决办法:https://www.ikjzd.com/articles/100998
口述实录:一个少妇的疯狂出轨生活:http://lady.shaoqun.com/a/72533.html
在宿舍被男友抱起来啪 把我内裤拨到侧面直接做:http://lady.shaoqun.com/m/a/248348.html
小舅子媳妇用胸撩拨 与我激情缠绵(2/2):http://lady.shaoqun.com/m/a/49359.html
它们总是射精太快。大概是因为他们吧:http://lady.shaoqun.com/a/405815.html
第一次性生活需要注意什么:http://lady.shaoqun.com/a/405816.html
射精太快是怎么造成的?这四个激励不可忽视:http://lady.shaoqun.com/a/405817.html
男性射精是高潮吗?:http://lady.shaoqun.com/a/405818.html
没有评论:
发表评论