0

我正在为 vb.net 中的温度刻度盘创建一个 Windows 形式的自定义 WPF 控件。当我尝试使用ElementHost在 Windows 窗体中添加 WPF 控件时,我收到错误消息“确保类型具有默认构造函数”。是的,我已经添加WindowsFormsIntegration.dll到我的项目参考资料中。

自定义控件的VB代码

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 代码

<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>

请帮我解决错误。

先感谢您

4

0 回答 0