ReportViewer styles affect too much?

1 Answer 53 Views
Report Viewer - WPF Styling
Bradley
Top achievements
Rank 2
Iron
Iron
Iron
Bradley asked on 12 Sep 2024, 08:47 PM

I'm incorporating a ReportViewer into my WPF app.  To do so, it seems I must include the following:

<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" />

However, including those seems to change a lot of other styles in my application that I'd rather not have changed.  I'd like to limit the scope of those changes to the ReportViewer itself.  Because, in the instance I'm working on right now, my ReportViewer is the only thing in a TabItem, I can put those resources in the TabItem, but then they'll be sprinkled throughout my app.

As you've likely figured out, I'm not the best at working with styles, but what I'd like to know is how to include those without their impacting anything else.

Thanks in advance!

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 17 Sep 2024, 12:17 PM

Hello Bradley,

Thank you for the provided information!

Let me start by mentioning that the WPF Report Viewer supports other themes as well, not only the Fluent theme. If the problem is that you are using another Telerik theme in the application, it is likely supported by our WPF Report Viewer component.

You may check the installation folder for details on what themes are supported by the report viewer - C:\Program Files (x86)\Progress\Telerik Reporting 2024 Q3\Wpf\Themes.

With that being said, if you do not wish to load the styles when the application starts, you may do so when the window with the report viewer is loaded through the code behind, please have a look at the second approach from the Use styles from XAML files in Telerik WPF Report Viewer - Telerik Reporting KB article for more details on how to implement it.

When you close the window or unload the viewer, you can clear the Application.Current.Resources.MergedDictionaries collection or remove the viewer's XAML resources (theme).

I hope that the provided information and suggestions are helpful. Please let me know if you have any questions.

Regards,
Dimitar
Progress Telerik

Stay tuned by visiting our roadmap and feedback portal pages, enjoy a smooth take-off with our Getting Started resources, or visit the free self-paced technical training at https://learn.telerik.com/.
Bradley
Top achievements
Rank 2
Iron
Iron
Iron
commented on 17 Sep 2024, 03:55 PM

This may be my lack of understanding or knowledge with respect to styling Telerik components.  What I want is styles that only affect the report viewer, not the rest of the application.  Perhaps I don't need all five of those resource dictionaries.  Unfortunately I haven't figured out how to get the report viewer to show without them.

It's not a matter of when the styles/themes are loaded.  It's a matter of what they affect.  I don't want every TextBox in my application to be affected by the styles I use for the viewer.

So, to rephrase my question, is there a minimal set of resource dictionaries or styles I need to include that will make the viewer visible without impacting the rest of my application?  If so, what is it?

Lance | Senior Manager Technical Support
Telerik team
commented on 17 Sep 2024, 07:36 PM

Hi Bradley, this is happening because there are implicit styles in 

<ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Fluent/System.Windows.xaml" />

Those implicit styles target those types you don't want to be styled.

Solution

ResourceDictionaries are hierarchically scoped in XAML. When merging in App.xaml, those styles are scoped for the entire application.

However, if you define the MergedDictionaries in the same view as the ReportViewer, then it would be scoped on only that view (and any child views)

Let's say for example:

  • You have the ReportViewer defined in a UserControl or Window named "MyReportViewer"
  • You can comment out (or cut & paste) the merged resources from App.xaml into the MyReportViewer.xaml.

MyReportViewer.xaml would now look like this:

<UserControl x:Class="SqlDataSource.Net8.MyReportViewer"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:tr="http://schemas.telerik.com/wpf"
        xmlns:telerikReporting="clr-namespace:Telerik.Reporting;assembly=Telerik.Reporting"
        mc:Ignorable="d"
        Title="MyReportViewer" Height="600" Width="800">
        
    <UserControl.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>
    </UserControl.Resources>

    <Grid Margin="20">
         <tr:ReportViewer x:Name="ReportViewer1" HorizontalAlignment="Stretch">
             <tr:ReportViewer.ReportSource>
                 <telerikReporting:UriReportSource Uri=".\ForBradley.trdp" />
             </tr:ReportViewer.ReportSource>
         </tr:ReportViewer>
     </Grid>
</UserControl>

and App.xaml now looks like this:

<Application x:Class="SqlDataSource.Net8.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
   
   <Application.Resources>
       <!-- moved to  MyReportViewer.xaml
       <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>


Tags
Report Viewer - WPF Styling
Asked by
Bradley
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dimitar
Telerik team
Share this question
or