小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

C#下WPF中調(diào)用WinForm控件

 芥子c1yw3tb42g 2023-11-02 發(fā)布于陜西
最近在C#下調(diào)用NPlot生成股票K線圖,由于用的WPF框架,而NPlot是基于WinForm開發(fā)的。所以不能直接引用。具體做法如下:   NPlot源碼Microsoft .NET Framework 4.5版
1、引入DLL
創(chuàng)建工程后需要引入WindowsFormsIntegration.dll和System.Windows.Forms.dll兩個Dll。WindowsFormsIntegration.dll負責整合WPF和Windows。
2、在xaml中添加命名空間標簽
xmlns : WinFormIntegration ='clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration'
3、添加宿主容器
< WinFormIntegration : WindowsFormsHost x : Name ='winFormsHost' Grid.Row ='1' Width ='Auto' Grid.ColumnSpan ='2'>
      <!--在此添加WinForm控件-->
</ WinFormIntegration : WindowsFormsHost >
本例完整的xaml文件:
< Window x : Class ='AxyDeal.MainWindow'
        xmlns : x =' http://schemas.microsoft.com/winfx/2006/xaml' ;
        Title ='MainWindow' Height ='600' Width ='1080'
        xmlns : local ='clr-namespace:AxyDeal.comcontrol'
         xmlns : WinFormIntegration ='clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration'
        >
    < Grid >
        < DockPanel >
            < Menu DockPanel.Dock ='Top'>
                < MenuItem Header ='文件'>
                    < MenuItem Header ='打開'>
                        < MenuItem Header ='1.txt'></ MenuItem >
                        < MenuItem Header ='2.txt'></ MenuItem >
                        < MenuItem Header ='3.txt'></ MenuItem >
                    </ MenuItem >
                    < MenuItem Header ='退出' Name ='miExit' Click ='miExit_Click'></ MenuItem >
                </ MenuItem >
                < MenuItem Header ='編輯'>
                    < MenuItem Header ='復(fù)制'></ MenuItem >
                    < MenuItem Header ='粘貼'></ MenuItem >
                </ MenuItem >
            </ Menu >
            < ToolBar DockPanel.Dock ='Top' Height ='40'>
                < Button >
                    < Image Source ='images/logo_email.png'></ Image >
                </ Button >
                < Button >
                    < Image Source ='images/logo_dropbox.png'></ Image >
                </ Button >
                < Button >
                    < Image Source ='images/logo_evernote.png'></ Image >
                </ Button >
            </ ToolBar >
            < TabControl DockPanel.Dock ='Left' >
                < TabItem Header ='TabItem'>
                    < Grid Background ='#FFE5E5E5'/>
                </ TabItem >
                < TabItem Header ='TabItem'>
                    < Grid Background ='#FFE5E5E5'/>
                </ TabItem >
            </ TabControl >
            < Grid Height ='Auto' Width ='Auto'   Background ='AliceBlue'>
                < Grid.RowDefinitions >
                    < RowDefinition Height ='Auto'></ RowDefinition >
                    < RowDefinition ></ RowDefinition >
                </ Grid.RowDefinitions >
                < Grid.ColumnDefinitions >
                    < ColumnDefinition ></ ColumnDefinition >
                    < ColumnDefinition ></ ColumnDefinition >
                </ Grid.ColumnDefinitions >
                < local : TickerControl x : Name ='tickerControl' Grid.Row ='0' Height ='50' Grid.ColumnSpan ='2' Grid.RowSpan ='1' Width ='686' VerticalAlignment ='Top' HorizontalAlignment ='Center' Visibility ='Visible' Margin ='1,0,0,0' ></ local : TickerControl >
                < WinFormIntegration : WindowsFormsHost x : Name ='winFormsHost' Grid.Row ='1' Width ='Auto' Grid.ColumnSpan ='2'>
                    <!--在此添加WinForm控件-->
                </ WinFormIntegration : WindowsFormsHost >               
            </ Grid >
        </ DockPanel >
    </ Grid >
</ Window >
4、在代碼中引入WinForm控件
這里聲明了兩個要引入的變量
//Form實例
private Form kLineForm = new Form();
//要引入的NPlot控件
private NPlot.Windows.PlotSurface2D KLinePS;
然后在MainWindow方法中添加:
//把Form添加的xaml中創(chuàng)建的宿主容器
this.winFormsHost.Child = this.kLineForm;
KLinePS = new NPlot.Windows.PlotSurface2D();
//把NPlot控件添加的Form中
this.kLineForm.Controls.Add(this.KLinePS);
至此可以在WPF中任意使用NPlot了。
使用NPlot是一款免費又開源.Net平臺下的圖表控件,能做各種曲線圖,柱狀圖,餅圖,散點圖,股票圖等。

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多