温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Winform和WPF下如何调用ComponentOne的控件

发布时间:2021-11-30 16:37:20 来源:亿速云 阅读:275 作者:小新 栏目:编程语言

这篇文章主要为大家展示了“Winform和WPF下如何调用ComponentOne的控件”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Winform和WPF下如何调用ComponentOne的控件”这篇文章吧。

Step 1

首先,我们还是把两个平台的基本通信通道搭建起来,很简单,网上有很多步骤,总结起来主要分三步:

  1. 添加两个引用:WindowsFormsIntegration.dll(负责整合WPF和Windows)、System.Windows.Forms.

  2. 在 XAML文件中添加两个引用(粗体部分):

 <Window x:Class="CrossBowDemo.MainWindow"xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"xmlns:wf ="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Title="Hosting Windows Forms Control In WPF"Height="300"Width="650"ResizeMode="NoResize"Loaded="WindowLoadedHandler"> < /Window>

解释一下,这段代码真正起作用的是这个引用WindowsFormsIntegration.dll,而这个引用System.Windows.Forms 指的是Winform里面的微软的原生态控件,所以在用到ComponentOne时,可以不引用它。

我们先看一个示例:通过微软原生态控件在WPF中使用Winform,代码如下:

<wfi:WindowsFormsHost>
        <wf:DataGridView x:Name="Dg"  Dock="Fill" SelectionMode="FullRowSelect">            
        </wf:DataGridView>
    </wfi:WindowsFormsHost>

WindowsFormsHost其实是Winform在WPF的容器,所以Winform的控件显示都要在这个容器里面。

Setp2

上面我们说了,我们以FlexReport为介质进行通信,那我们需要准备的几个小步骤:

  1. Winform下FlexReport的模板

  2. 相关引用

Winform和WPF下如何调用ComponentOne的控件

注意:这里面的引用是Winform的引用。同样,我们需要在xmal中引用:

xmlns:cc11="clr-namespace:C1.Win.FlexViewer;assembly=C1.Win.FlexViewer.4"

在布局中添加可供报表预览的控件

<Grid>
        <wfi:WindowsFormsHost>
            <cc11:C1FlexViewerPane   x:Name="flexViewerPane"  ></cc11:C1FlexViewerPane>
        </wfi:WindowsFormsHost>
    </Grid>

Setp3

我们在后台加载报表

private C1FlexReport _report;    public Window1()
    {
        InitializeComponent();
        _report = new C1FlexReport();
 // load report definition from resources
        Assembly asm = Assembly.GetExecutingAssembly();        
 using (Stream stream = asm.GetManifestResourceStream("WpfApp1.Resources.FlexCommonTasks.flxr"))
            _report.Load(stream, "Chart2D");        // assign report to the preview pane
        flexViewerPane.DocumentSource = null;
        flexViewerPane.DocumentSource = _report;
    }

注:切记,这里面的报表是Winform平台下的

到这一步,我们工作完成了一大半,还差最后一步点石成金的步骤。很多人以为在这就结束了,但是我们要考虑 ComponentOne License 授权的问题,如何把Winform 的授权在WPF下注册,其实很简单,因为 .NET 的license机制一样,我们只需用同样的方式去注册控件的license ,不过这里推荐手动注册,这很重要,因为一不小心,就会报lc.exe=-1的错误

这里我们都用到了

  • C1FlexViewerPane

  • C1FlexReport

所以我们在license文件中写如下注册信息

C1.Win.FlexReport.C1FlexReport, C1.Win.FlexReport.4 C1.Win.FlexViewer.C1FlexViewerPane, C1.Win.FlexViewer.4

至此,我们就大功告成了。

以上是“Winform和WPF下如何调用ComponentOne的控件”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI