具有属性的自定义MarkupExtension

时间:2016-05-19 08:14:11

标签: wpf vb.net markup-extensions

我创建了一个MarkupExtension,它公开了类型IValueConverter的Converter属性,visual studio中的Intellisens找到了它,但是当我尝试编译时,我收到以下错误:Unknown property 'Converter' for type 'MS.Internal.Markup.MarkupExtensionParser+UnknownMarkupExtension' encountered while parsing a Markup Extension.

EnumItemSourceBinding:

Public Class EnumItemSourceBinding
    Inherits MarkupExtension
    Implements INotifyPropertyChanged

    Private mEnumType As Type
    Private mConverter As IValueConverter

    <DefaultValue(CObj(Nothing))>
    Public Property EnumType As Type
        Get
            Return mEnumType
        End Get
        Set(value As Type)
            mEnumType = value
            OnPropertyChanged(NameOf(EnumType))
            mBindingChanged = True
        End Set
    End Property

    <DefaultValue(CObj(Nothing))>
    Public Property Converter As IValueConverter
        Get
            Return mConverter
        End Get
        Set(value As IValueConverter)
            mConverter = value
            OnPropertyChanged(NameOf(Converter))
            mBindingChanged = True
        End Set
    End Property

    Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged

    Public Sub New()
        MyBase.New()

    End Sub

    Public Sub New(enumType As Type)
        MyBase.New()
        mEnumType = enumType
    End Sub

    Private Sub OnPropertyChanged(ByVal propertyName As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
    End Sub
End Class

的Xaml: {local:EnumItemSourceBinding {x:Type local:BoundTextFields}, Converter={StaticResource EnumToTextConverter}}

为什么会出现编译错误?

1 个答案:

答案 0 :(得分:0)

您似乎无法在要使用它的同一个程序集中定义MarkupExtension,所以我不得不拆分它。