zoukankan      html  css  js  c++  java
  • 如何在WPF中调用Winform控件

    原文地址:http://hi.baidu.com/stuoopluwqbbeod/item/32ec38403da42ee2bcf45167

    功能实现主要分三步:
    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>

    3、在XAML编码区实现你想添加的控件:

        原文添加的是 DataGridView控件:
       <wfi:WindowsFormsHost>
           <!-- Set some properties on Windows Forms control in Xaml -->
          <wf:DataGridView x:Name="dataGridView" Dock="Fill" SelectionMode="FullRowSelect"/>
        </wfi:WindowsFormsHost>
    效果图:



    本人添加的是 NumericUpDown控件:

        <Grid Height="0" Margin="146,0,0,116" MinHeight="20" MinWidth="20" Name="grid1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="50">
          <wfi:WindowsFormsHost>
            <wf:NumericUpDown x:Name="nupCounter" Maximum="100"></wf:NumericUpDown>
          </wfi:WindowsFormsHost>
        </Grid>
    效果图:



    在本人的代码中Grid的作用相当于Web页面中用来布局的Table。 此处加上Grid是为了方便移动控件的位置。

    原文地址:http://hi.baidu.com/stuoopluwqbbeod/item/32ec38403da42ee2bcf45167

  • 相关阅读:
    配置和兼容性测试的区别是什么?
    7 天内免登陆,测试要怎么去测试?
    在测试“支付网关”过程中的5个要点
    Hibernate入门与简谈
    jQuery专题
    Java反射机制专题
    Java IO流
    EL和JSTL专题
    泛型(Generic)
    Java异常处理
  • 原文地址:https://www.cnblogs.com/IT-Bear/p/3497900.html
Copyright © 2011-2022 走看看