如何爲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中文網,獲取第一手最新產品資訊!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章