Building WPF control in Windows Form: Error message saying "make sure the type has a default constructor"

260 Views Asked by At

I am creating a custom WPF control in windows form for a temperature dial in vb.net. When I try to add the WPF control in windows form using ElementHost, I Get the error message "Make sure the type has a default constructor". And yes I have added WindowsFormsIntegration.dll to my project's references.

VB Code for Custom Control

Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Navigation
Imports System.Windows.Shapes
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ComponentModel
Imports System.Windows.Forms.UserControl
Imports System.Windows.Media.Animation
Imports System.Windows.Forms.Integration

Namespace CSV_FILE

    Public Class Temperature_Dial
        Inherits System.Windows.Forms.UserControl
        Public pointervalue As Double
        Private arrowPointer As System.Windows.Shapes.Rectangle
        Public Sub Temperature_Dial()
            InitializeComponent()
        End Sub

        Public Sub InitializeComponent()
            ' Throw New NotImplementedException()
        End Sub

        Public Sub changevalue()
            Dim rotate As RotateTransform = New RotateTransform(pointervalue)
            arrowPointer.RenderTransform = rotate

        End Sub
    End Class
End Namespace

XML Code

<UserControl x:Class="Temperature_Dial"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:CSV_FILE"
             mc:Ignorable="d" Width="368.545" Height="463.273">
    
        <Grid x:Name="Dial" Margin="-13,-66,0,-50" HorizontalAlignment="Left" Width="379">
        <Grid.Background>
            <ImageBrush ImageSource="Temp_gauge_without_needles.png" Stretch="UniformToFill"/>
        </Grid.Background>
        
            <Rectangle x:Name="Value" HorizontalAlignment="Left" Height="197" Margin="90,144,0,0" VerticalAlignment="Top" Width="217">
            <Rectangle.Fill>
                <ImageBrush ImageSource="dial_values.png" Stretch="UniformToFill"/>
            </Rectangle.Fill>
        </Rectangle>
            
        <Rectangle x:Name="arrowPointer" HorizontalAlignment="Left" Height="34" Margin="87,242,0,0" VerticalAlignment="Top" Width="149" RenderTransformOrigin="0.77,0.48">
            <Rectangle.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="2612.226"/>
                    <TranslateTransform X="-3.86853" Y="-0.314352"/>
                </TransformGroup>
            </Rectangle.RenderTransform>
            <Rectangle.Fill>
                <ImageBrush ImageSource="NEEDLE.png" Stretch="UniformToFill"/>
            </Rectangle.Fill>
        </Rectangle>

    </Grid>
  
</UserControl>

Please help me to resolve the error.

Thank you in advance

0

There are 0 best solutions below