导入自定义Wpf控件库DLL

时间:2017-02-13 16:17:02

标签: wpf vb.net dll

我制作了一个WpfControlLibrary DLL,以便在WindowsForm项目中导入自定义ProgressBar。问题是,编译,一切正常。 但是,当我尝试通过这样做导入我的DLL ToolBox->右键单击 - >选择元素...-> WPF组件 - >浏览...->选择dll->确定 它会返回此错误 ' ... ... pathofthedll'不包含可以在工具箱中插入的任何组件。

这里是WpfControlLibrary的代码

<ProgressBar xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="NewProgressBar"
  x:Name="ProgressBar" 
  Margin="20"
  Value="{Binding ElementName=progress, Path=Value}" Height="30" IsIndeterminate="False" Foreground="{DynamicResource BrushRed}" Width="300">
    <ProgressBar.Resources>
        <SolidColorBrush x:Key="BrushRed" Color="#FFD30101"/>
        <SolidColorBrush x:Key="BrushGreen" Color="#FF27D301"/>
        <SolidColorBrush x:Key="BrushYellow" Color="#FFD3D301"/>
    </ProgressBar.Resources>

Public Class NewProgressBar
Inherits ProgressBar

Private mColor1 As SolidColorBrush
Private mColor2 As SolidColorBrush
Private mColor3 As SolidColorBrush
Private mMaxValue As Integer = 100
Private mCurrentValue As Double = 0


Public Sub New(ByVal color1 As String, ByVal color2 As String, ByVal color3 As String)

    InitializeComponent()

    Dim Brush1 As New SolidColorBrush
    Brush1.Color = ConvertToRbg(color1)
    Me.mColor1 = Brush1

    Dim Brush2 As New SolidColorBrush
    Brush2.Color = ConvertToRbg(color2)
    Me.mColor2 = Brush2

    Dim Brush3 As New SolidColorBrush
    Brush3.Color = ConvertToRbg(color3)
    Me.mColor3 = Brush3

    Me.Resources.Add("BrushRed", Brush1)
    Me.Resources.Add("BrushYellow", Brush2)
    Me.Resources.Add("BrushGreen", Brush3)

End Sub

Public Property GetColor1() As String
    Get
        Return mColor1.Color.ToString
    End Get
    Set(value As String)
        Dim Brush As New SolidColorBrush
        Brush.Color = ConvertToRbg(value)
        Me.mColor1 = Brush
    End Set
End Property

Public Property GetColor2() As String
    Get
        Return mColor2.Color.ToString
    End Get
    Set(value As String)
        Dim Brush As New SolidColorBrush
        Brush.Color = ConvertToRbg(value)
        Me.mColor2 = Brush
    End Set
End Property

Public Property GetColor3() As String
    Get
        Return mColor3.Color.ToString
    End Get
    Set(value As String)
        Dim Brush As New SolidColorBrush
        Brush.Color = ConvertToRbg(value)
        Me.mColor3 = Brush
    End Set
End Property

Public Property GetMaxValue() As Integer
    Get
        Return mMaxValue
    End Get
    Set(value As Integer)
        mMaxValue = value
    End Set
End Property

Private Function ConvertToRbg(ByVal HexColor As String) As Color
    Dim Red As String
    Dim Green As String
    Dim Blue As String
    HexColor = Replace(HexColor, "#", "")
    Red = Val("&H" & Mid(HexColor, 1, 2))
    Green = Val("&H" & Mid(HexColor, 3, 2))
    Blue = Val("&H" & Mid(HexColor, 5, 2))
    Return Color.FromRgb(Red, Green, Blue)
End Function

Public Sub ChangeColor()
    Dim prgrss As Double = mCurrentValue / 100

    Dim redbrsh As SolidColorBrush = Me.Resources("BrushRed")
    Dim grnbrsh As SolidColorBrush = Me.Resources("BrushGreen")
    Dim ylwbrsh As SolidColorBrush = Me.Resources("BrushYellow")


    If prgrss = 1D Then

        Me.Foreground = grnbrsh

    ElseIf prgrss >= 0.95D And prgrss < 1D Then

        Me.Foreground = ylwbrsh
    Else
        Me.Foreground = redbrsh
    End If

    Dim number As Integer = prgrss



End Sub

Public Sub ChangeValue(ByVal value As Integer)
    Me.Value = (100 * value) / mMaxValue
    mCurrentValue = Me.Value
End Sub

结束班

0 个答案:

没有答案