zoukankan      html  css  js  c++  java
  • WPF和WINFORM的互操作

    在WPF中使用Winform控件

    <Window x:Class="WPFApplication.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:winforms="clr-namespace:WindowsFormsControl;assembly=WindowsFormsControl"
    xmlns:my="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
    Title="Window1" Height="300" Width="300" >
    <Grid>
    <my:WindowsFormsHost Name="windowsFormsHost1">
    <winforms:UserControl1 x:Name="myControl" ButtonText="Click me!" />
    </my:WindowsFormsHost>
    </Grid>
    </Window>

    其中xmlns:winforms=…为导入命名空间和程序集名称
    <Grid>中的标记为winform用户控件

     

    Winform中使用WPF控件,需要添加以下几个与WPF相关的引用:
    * PresentationCore
    * PresentationFramework
    * System.Xaml
    * WindowsBase
    * WindowsFormsIntegration

    void WPFInWinform()
    {
    //创建WPF控件
    System.Windows.Controls.TextBox wpfTxt = new System.Windows.Controls.TextBox();
    wpfTxt.Name = "txName";
    wpfTxt.Text = "WPF TextBox";
    //创建使用WPF控件的容器
    ElementHost elementHost = new ElementHost();
    elementHost.Dock = DockStyle.None;
    elementHost.Width = 150;
    elementHost.Height = 50;

    elementHost.Child = wpfTxt;
    this.Controls.Add(elementHost);
    }

    可以在界面上面选择Child

    image

    image

  • 相关阅读:
    HTC G7 搜索和感光按键修改
    Delphi开源组件SynEdit
    (转)Delphi获取windows系统版本信息
    TDateTime转UTC的时间差
    Windows7 C盘无法读写文件
    Convert UTC string to TDatetime in Delphi
    delphi抓全屏图,游戏窗口,游戏Client窗口
    ADO Table Locate
    Delphi与管道操作
    Delphi从UTC (GMT)返回时差
  • 原文地址:https://www.cnblogs.com/jx270/p/3166173.html
Copyright © 2011-2022 走看看