Disabling the Ctrl+F key in WPF Reportviewer

2 Answers 193 Views
.NET Framework Report Viewer - WPF
Andrew
Top achievements
Rank 1
Iron
Andrew asked on 06 Dec 2022, 04:03 AM

Hello 

 

Is there a way to disable the search shortcut in WPF Reportviewer,

We have hidden the toolbar button for search (It does not work if the Reportviwer is in a WPF class. Null Exception),

but would also like stop the user from pressing the Ctrl+F and getting the Null Exception error.

Has anyone know how this can be achieved?

We have set up Windows.InputBindings as well as a dummy command with gesture capture, but the CTRl+F in reportviewer seems to circumvent these.

Any ideas?

Thanks

Andrew

 

 

2 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 08 Dec 2022, 03:53 PM

Hi Andrew,

There is no way to override this as far as I am aware, it would probably be easier to instead fix the search.

Please look into the NullReferenceException occurs in WPF report viewer after invoking search dialog - Telerik Reporting KB article for details on what you may try.

Please make sure that you have merged all necessary resources, for example, in the App.xaml file:

<Application x:Class="CSharp.NetFramework.WpfIntegrationDemo.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="Window1.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Fluent/System.Windows.xaml" />
                <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Fluent/Telerik.Windows.Controls.xaml" />
                <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Fluent/Telerik.Windows.Controls.Input.xaml" />
                <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Fluent/Telerik.Windows.Controls.Navigation.xaml" />
                <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Fluent/Telerik.ReportViewer.Wpf.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

I hope this will help. If further assistance is needed, please send a runnable project where the issue is reproduced.

Regards,
Dimitar
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
0
Andrew
Top achievements
Rank 1
Iron
answered on 08 Dec 2022, 11:52 PM

Thank you for your response Dimitar.

When we use a WPF application, the Search works correctly, only when the project is a WPF Class Library is is an issue.

We are using Reporting v 14.1.20.618. We used this XAML rather then the v12.1.18.516 as mentioned above.  They are quite diffrect in their definitions of SearchDialog bu the approach is the same. We took the base xaml and added our extra code we required.

We use implicit themes, but for testing we have changed this to use the Telerik,ReportViewer.Wpf.Themes.dll.  Same issue.

We would prefer to use the implicit themes as we added an exit button and headings to the toolbar.  All these work as expected.

There is no App.xaml as this is a class and the following is in the xaml for the displayable control:

<Window x:Class="KTRepPreview"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    xmlns:tr="clr-namespace:Telerik.ReportViewer.Wpf;assembly=Telerik.ReportViewer.Wpf"
   Title="MainWindow" Height="350" Width="922" Name="frmPreview" WindowState="Maximized" WindowStartupLocation="CenterScreen" ShowInTaskbar="False" ResizeMode="CanResize" WindowStyle="None" >
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
           <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Windows8Touch/System.Windows.xaml" />
                <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Windows8Touch/Telerik.Windows.Controls.xaml" />
                <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Windows8Touch/Telerik.Windows.Controls.Input.xaml" />
                <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Windows8Touch/Telerik.Windows.Controls.Navigation.xaml" />
                <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Windows8Touch/Telerik.ReportViewer.Wpf.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Grid">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <tr:ReportViewer  Name="MyReportViewer" Grid.Row="1" />
    </Grid>
</Window>

 

The reportviewer displays in the designer correctly and runs fine, only the search is an issue, paging, zoom, forward/back all fine.

All other reportviewer toolbar options work fine, When you press search this is the Stacktrace :

see attached file SearchDialogTrace.txt

 

Any other assistance is very welcome,

Thank you

Andrew

Dimitar
Telerik team
commented on 13 Dec 2022, 02:20 PM

Hi Andrew,

Honestly, I am not too familiar with using WPF in Class Library project, however, it seems there is some XAML that you are somehow able to successfully display in a window. For that reason, you should be able to catch the Window's Keyboard.PreviewKeyDown Attached Event which should allow you to handle the Ctrl + F combination, for example:

        private void HandleKeyDownEvent(object sender, KeyEventArgs e)
        {

            if (e.Key == Key.F && Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
            {
                MessageBox.Show("CTRL + F captured");
            }
        }
<Window PreviewKeyDown="HandleKeyDownEvent" ... ></Window>

I tested it locally with a normal WPF application and was able to successfully capture the event and not trigger the search of the Report Viewer. I do not see an obvious reason why this wouldn't work for your scenario considering that you are able to provide any XAML to it.

Please test the suggested approach and let me know how it goes.

 

Andrew
Top achievements
Rank 1
Iron
commented on 14 Dec 2022, 12:27 AM

Thank you Dimitar

This works to catpure the Ctrl F and not trigger the error.

We will keep tryng to resolve the Search issue, but this will stop it from occuring with the key shortcut

 

Regards

Andrew

 

Tags
.NET Framework Report Viewer - WPF
Asked by
Andrew
Top achievements
Rank 1
Iron
Answers by
Dimitar
Telerik team
Andrew
Top achievements
Rank 1
Iron
Share this question
or