RDLC系列之五 初试XAML

简介: 本章只讲解xaml部分,其余都和winform下一样 1.xaml代码 2.后台代码 using System; using System.

本章只讲解xaml部分,其余都和winform下一样

1.xaml代码

<Window x:Class="RDLC.WPF.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:rv="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"
        Loaded="Window_Loaded" Closed="Window_Closed" 
        Title="MainWindow" Height="350" Width="525">
    <WindowsFormsHost Name="windowsFormsHost">
        <rv:ReportViewer x:Name="reportView" /> 
    </WindowsFormsHost>
</Window>

2.后台代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Reporting.WinForms;

namespace RDLC.WPF
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //代码区域

            this.reportView.RefreshReport();
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            this.reportView.LocalReport.Dispose();
            this.reportView.LocalReport.ReleaseSandboxAppDomain();
        }

    }
}

 

3.DLL引用

MainWindow.xaml:

System.Windows.Forms

WindowsFormsIntegration  (.NET 4.0 才有,直接在程序集里面搜索)

MainWindow.xaml.cs:

Microsoft.ReportViewer.Common.dll、 Microsoft.ReportViewer.ProcessingObjectModel.dll、 Microsoft.ReportViewer.WebForms.dll和Microsoft.ReportViewer.WinForms.dll

注意:本次测试的Microsoft.ReportViewer的dll为版本号为11.0,试过使用9.0的,但是this.reportView.LocalReport.ReleaseSandboxAppDomain() 无法使用。

 

4.报表的工具栏

操作方法:在工具栏选择或取消相应的属性

例:不显示刷新按钮和导出按钮

 <rv:ReportViewer x:Name="reportView" ShowRefreshButton="False" ShowExportButton="False"  />

 

相关文章
|
11月前
|
C# Windows
2000条你应知的WPF小姿势 基础篇<74-77 WPF 多窗口Tips>
2000条你应知的WPF小姿势 基础篇<74-77 WPF 多窗口Tips>
89 0
|
C#
艾伟_转载:WPF/Silverlight陷阱:XAML自定义控件的嵌套内容无法通过名称访问
为了说明这个问题,假定我们需要实现一个具有特殊功能的按钮控件。编写Xaml文件如下: Button> 对 Code Behind类,唯一的改动是把向导生成的基类从UserControl改成Button: public partial class XamlButton : Button{    ...
1069 0
|
C#
WPF - 资源收集
原文:WPF - 资源收集   OpenExpressApp的UI现在是使用WPF,所以熟悉WPF是必须的,以下我将可能用到的一些相关内容随时记录下来,以备查阅。此篇文章将不断更新,感兴趣的可以看看,也欢迎大家补充。
1173 0
|
C# C++
WPF编游戏系列 之四 用户控件
原文:WPF编游戏系列 之四 用户控件        在上一篇《WPF编游戏系列 之三 物品清单》中,对物品清单进行了演示,其中反复用到了同一组控件(如下图),而且 颜昌钢也指出在3.2.2中使用的C#代码过多,其实我在写这些代码时也有同感,的确很繁琐也不好维护。
606 0
|
C# 前端开发
WPF编游戏系列 之二 图标效果
原文:WPF编游戏系列 之二 图标效果        本篇将要实现图标的两个效果:1. 显示图标标签,2. 图标模糊效果。在上一篇中提到Image没有HTML 的Title属性(在MSDN中也没找到类似的属性),所以本篇将自行制作一个标签,它的功能是当鼠标移动到图标上方时会显示该图标的Tag说明,并且该图标模糊显示,如下图对比所示。
757 0
|
开发框架 移动开发