ActiveReports 8 > ActiveReports User Guide > Samples and Walkthroughs > Walkthroughs > Common Walkthroughs > WPF > WPF Viewer |
The ActiveReports WPF Viewer is a custom control that allows to easily view both section and page report layouts.
This walkthrough is split up into the following activities.
When you have completed this walkthrough, you will have the ActiveReports WPF Viewer displaying a report that looks similar to the following.
To create a WPF application in Visual Studio 2010
To add the WPF Viewer control
Property Name | Property Value |
---|---|
HorizontalAlignment | Stretch |
VerticalAlignment | Stretch |
Margin | 0 |
To load a report to the WPF Viewer
Visual Basic.NET code. Paste INSIDE the viewer1_Loaded event in MainWindow.xaml.vb. |
Copy Code
|
---|---|
Viewer1.LoadDocument("rptSingleLayout.rdlx") |
C# code. Paste INSIDE the viewer1_Loaded event in MainWindow.xaml.cs. |
Copy Code
|
---|---|
viewer1.LoadDocument("rptSingleLayout.rdlx"); |
Note: For an example of other ways to bind a report to the WPF Viewer, see the LoadDocument method in the Class Library documentation. |
Note: To avoid evaluation banners appearing at runtime, license your ActiveReports WPF Application project. You can find information on licensing in License Your ActiveReports. |
To view the report
To customize the 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).
To add the customization template to the WPF project
Paste to the XAML view of MainWindow.xaml before the opening <Grid> tag |
Copy Code
|
---|---|
<Window.Resources> <ResourceDictionary Source="DefaultWPFViewerTemplates.xaml" /> </Window.Resources> |
To customize the WPF Viewer sidebar
To add a customized button to the WPF Viewer toolbar
To write the code in Visual Basic.NET
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("GrapeCity is the world's largest component vendor.", "About Us", MessageBoxButton.OK) End Sub |
To write the code in C#
C# code. Add after the statement using System.Text; |
Copy Code
|
---|---|
using System.Windows.Input; using System.Windows; |
C# code. Add to MyCommand.cs |
Copy Code
|
---|---|
public class MyCommand : ICommand { public bool CanExecute(object parameter) { return true; } public void Execute(object parameter) { MessageBox.Show("GrapeCity 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" /> |
To remove the Refresh button from the WPF Viewer toolbar
XML code. Add to DefaultWpfViewerTemplates.xaml |
Copy Code
|
---|---|
<Button Command=... Visibility="Collapsed">
|