Let us see how we can customize different elements of WPF Viewer.
The ActiveReports WPF Viewer is a customizable control. You can easily change the look of the WPF Viewer and its elements, such as the error panel, search panel, sidebar and toolbar by modifying properties in the default WPF Viewer template (DefaultWPFiewerTemplates.xaml).
Once you copy the template, you can modify the default style and apply it to your viewer by creating the desired style and setting its Template property.
Note that while modifying the template, do not remove the required template parts. The required parts are usually marked with the prefix "PART_".
The template allows you to customize the appearance of viewer and take advantage of XAML-based styling.
Paste to the XAML view of MainWindow.xaml before the opening <Grid> tag |
Copy Code
|
---|---|
<Window.Resources>
<ResourceDictionary Source="DefaultWPFViewerTemplates.xaml" />
</Window.Resources>
|
Visual Basic.NET code. Add to MyCommand.vb |
Copy Code
|
---|---|
Implements ICommand Public Function CanExecute(ByVal parameter As Object) As Boolean Implements System.Windows.Input.ICommand.CanExecute Return True End Function Public Event CanExecuteChanged(ByVal sender As Object, ByVal e As System.EventArgs) Implements System.Windows.Input.ICommand.CanExecuteChanged Public Sub Execute(ByVal parameter As Object) Implements System.Windows.Input.ICommand.Execute MessageBox.Show("MESCIUS is the world's largest component vendor.", "About Us", MessageBoxButton.OK) End Sub |
C# code. Add after the statement using System.Text |
Copy Code
|
---|---|
using System.Windows.Input; using System.Windows; |
C# code. Add after the statement using System.Text |
Copy Code
|
---|---|
public class MyCommand : ICommand { public bool CanExecute(object parameter) { return true; } public void Execute(object parameter) { MessageBox.Show("MESCIUS is the world's largest component vendor.", "About Us", MessageBoxButton.OK); } public event EventHandler CanExecuteChanged; } |
XML code. Add to DefaultWpfViewerTemplates.xaml |
Copy Code
|
---|---|
<ResourceDictionary> ... xmlns:YourProjectName="clr-namespace:YourProjectName"> <YourProjectName:MyCommand x:Key="MyCommand" /> ... </ResourceDictionary> |
XML code. Add to DefaultWpfViewerTemplates.xaml before the closing Toolbar tag |
Copy Code
|
---|---|
<Button Command="{StaticResource MyCommand}" Content="About Us" /> |
XML code. Add to DefaultWpfViewerTemplates.xaml |
Copy Code
|
---|---|
<Button Command=... Visibility="Collapsed"> |