AABBbaby

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

如何为WPF数据网格创建自定义筛选器编辑器对话框?

下载DevExpress v20.2完整版

DevExpress技术交流群3:700924826      欢迎一起进群讨论

DevExpress WPF Subscription拥有120+个控件和库,将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpress WPF能创建有着强大互动功能的XAML基础应用程序,这些应用程序专注于当代客户的需求和构建未来新一代支持触摸的解决方案。 无论是Office办公软件的衍伸产品,还是以数据为中心的商业智能产品,都能通过DevExpress WPF控件来实现。

问题:

从v19.1开始,网格控件使用新的FilterEditorControl。UseLegacyFilterEditor设置为True,从而可以触发FilterEditorCreated事件。 如果要自定义新的FilterEditorControl,是否还有另一个事件可以使用?

希望能够创建由DxGrid控件使用的自定义FilterEditorControl对话框表单,使用更新的FilterEditorControl时,如何完成利用网格引发的事件来拦截创建的旧版FilterControl并将其注入自定义形式?

解决方案:

要完成此任务,可以使用TableView的FilterEditorDialogServiceTemplate属性,该属性将允许您重新定义FilterEditorContol的默认对话框服务。 此代码段演示了默认实现:

XAML

 

<dxg:TableView.FilterEditorDialogServiceTemplate>
<DataTemplate xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxfuit="http://schemas.devexpress.com/winfx/2008/xaml/core/filteringui/themekeys"
xmlns:dxn="http://schemas.devexpress.com/winfx/2008/xaml/core/internal">
<ContentControl>
<dx:DialogService DialogWindowStartupLocation="CenterOwner"
ViewTemplate="{DynamicResource {dxfuit:FilterEditorThemeKey ResourceKey=FilterEditorDialogServiceViewTemplate}}">
<dx:DialogService.DialogStyle>
<Style TargetType="{x:Type dx:ThemedWindow}">
<Setter Property="dxn:ThemedWindowOptions.ShowOverPopups" Value="True" />
<Setter Property="ShowInTaskbar" Value="False" />
<Setter Property="WindowStyle" Value="ToolWindow" />
<Setter Property="ShowIcon" Value="False" />
<Setter Property="UseLayoutRounding" Value="True" />
<Setter Property="Width" Value="500" />
<Setter Property="Height" Value="350" />
<Setter Property="MinWidth" Value="500" />
<Setter Property="MinHeight" Value="350" />
</Style>
</dx:DialogService.DialogStyle>
</dx:DialogService>
</ContentControl>
</DataTemplate>
</dxg:TableView.FilterEditorDialogServiceTemplate>

 

要显示自己的对话框按钮,您将需要启用ThemedWindowOptions.UseCustomDialogFooter属性:

XAML

 

<dx:DialogService.DialogStyle>
<Style TargetType="{x:Type dx:ThemedWindow}">
<Setter Property="dxn:ThemedWindowOptions.UseCustomDialogFooter" Value="True"/>
<.../>

 

之后,您可以覆盖FilterEditorTemplate属性并定义自定义按钮。

XAML

 

<dxg:TableView.FilterEditorTemplate>
<DataTemplate xmlns:dxfui="http://schemas.devexpress.com/winfx/2008/xaml/core/filteringui">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<dxfui:FilterEditorControl x:Name="filterControl" />
<dx:ThemedWindowDialogButtonsControl Grid.Row="1">
<dx:ThemedWindowDialogButton Margin="6 0 0 0"
Content="Cancel"
DialogResult="Cancel"
IsCancel="True" />
<dx:ThemedWindowDialogButton Margin="6 0 0 0"
Content="Test"
DialogResult="OK"
Command="{DXCommand Execute='@e(filterControl).ApplyFilter()'}"
IsDefault="True" />
</dx:ThemedWindowDialogButtonsControl>
</Grid>
</DataTemplate>
</dxg:TableView.FilterEditorTemplate>

 


上DevExpress中文网,获取第一手最新产品资讯!

posted on   AABBbaby  阅读(82)  评论(0编辑  收藏  举报

编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2020-05-11 现代Web开发堆栈工具DevExtreme 2020年首发v20.1.3
2020-05-11 Web界面开发工具!Kendo UI for jQuery数据管理:虚拟滚动
2018-05-11 DevExpress v17.2新版亮点——Data Access
点击右上角即可分享
微信分享提示