Results 1 to 3 of 3

Thread: Winform Control in WPF

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2015
    Posts
    171

    Winform Control in WPF

    Hello to everyone,
    I'm trying to use a winform control in WPF(I've not found good alternative).
    The control is the be.hexbox from sourceforge: https://sourceforge.net/projects/hexbox/files/hexbox/
    So I Start a new solution VB.net WPF and add WindowsFormsIntegration.dll reference.
    I also add reference to the control dll.
    the in XAML:
    Code:
    <Window x:Class="MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:wf="clr-namespace:Be.Windows.Forms;assembly=Be.Windows.Forms.HexBox"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:WpfApp2"
          
            mc:Ignorable="d"
            Title="MainWindow" Height="450" Width="800">
        <Grid>
            
            <WindowsFormsHost Name="TEST1">
    
                <wf:HexBox x:Name="HX" />
    
    
            </WindowsFormsHost>
        </Grid>
    </Window>
    but I get this error:
    Error XLS0502 The 'WindowsFormsHost' type does not support direct content.
    Any advice?

  2. #2

    Re: Winform Control in WPF

    Hii Hannibal Smith,

    Please refer to this link...
    https://www.c-sharpcorner.com/upload...ntrols-in-wpf/
    https://www.wpf-tutorial.com/misc-co...shost-control/

    This can be helpful to you!!

  3. #3
    New Member
    Join Date
    Oct 2020
    Location
    Europe
    Posts
    12

    Re: Winform Control in WPF

    Can reproduce the error when adding the reference to 'WindowsFormsIntegration' manually.
    After some testing: It needs at least an additional reference to 'System.Windows.Forms'

    But I normally let VS (2019) doing the Work:

    • New solution
    • Add Reference to HexBox
    • In editor select 'Grid'
    • From the Toolbox drag 'WindowsFormsHost' to the Grid -> References are added automatically
    • Place and size the WindowsFormsHost rectangle
    • In Properties search for 'Child', click 'New', select 'HexBox', click 'OK'
      -> creates 'xlns:Forms..' and <Forms:HexBox/> inside the FormsHost
    • Now the application starts without any errors
      (However HexBox is blank, seems that a file needs to be loaded first)


    This way VS adds also the references to 'System.Drawing' and 'UIAutomationProvider'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width