Question

I have a simple Button user Control that I use to aggregate all button functionality within my code:

Partial Public Class CommandButton
    Inherits UserControl
    Implements INotifyPropertyChanged
    Public ReadOnly ButtonCmdProperty As DependencyProperty = DependencyProperty.Register("ButtonCmd", GetType(ICommand), GetType(CommandButton), New PropertyMetadata(Nothing, New PropertyChangedCallback(AddressOf OnButtonCmdChanged)))
    Public ReadOnly ButtonTextProperty As DependencyProperty = DependencyProperty.Register("ButtonText", GetType(String), GetType(CommandButton), New PropertyMetadata("Undefined", New PropertyChangedCallback(AddressOf OnButtonTextChanged)))


    Public Sub New()
        InitializeComponent()
    End Sub


#Region "ButtonCmd"
    Public Property ButtonCmd As ICommand
        Get
            Return DirectCast(GetValue(ButtonCmdProperty), ICommand)
        End Get
        Set(value As ICommand)
            SetValue(ButtonCmdProperty, value)
        End Set
    End Property
    Private Sub OnButtonCmdChanged()
        OnPropertyChanged("ButtonCmd")
    End Sub
#End Region

#Region "ButtonText"
    Public Property ButtonText() As String
        Get
            Return DirectCast(GetValue(ButtonTextProperty), String)
        End Get
        Set(value As String)
            SetValue(ButtonTextProperty, value)
        End Set
    End Property
    Private Sub OnButtonTextChanged(d As DependencyObject, e As DependencyPropertyChangedEventArgs)
        OnPropertyChanged("ButtonText")
    End Sub
#End Region
End Class

Here is an example of where I use it in XAML code:

                                <controls:CommandButton x:Name="btnEdit" 
                                    HorizontalAlignment="Stretch" 
                                    VerticalAlignment="Stretch" 
                                    Height="Auto" 
                                    Width="100"
                                    Grid.Column="0" 
                                    ButtonCmd="{Binding EditButton.ButtonCmd}"
                                    ButtonText="{Binding EditButton.ButtonText, Mode=TwoWay}"
                                    ButtonTooltip="{Binding EditButton.ButtonTooltip}"
                                    IconHeight="{Binding EditButton.IconHeight}"
                                    IconWidth="{Binding EditButton.IconWidth}"
                                    IconSource="{Binding EditButton.IconSource}"
                                    IsVisible="{Binding EditButton.IsVisible}"
                                    ShowIcon="{Binding EditButton.ShowIcon}"
                                    ShowText="{Binding EditButton.ShowText}" />

(As you can see there are many other properties, but I have omitted them for brevity sake.) I have been working with the same code for over 2 years in VS2010 with no problems. Since upgrading to VS2013, every page where I use this button throws the error message:

Object of Type System.Windows.Data.BindingExpression cannot be converted to type System.String

on each binding. It doesn't appear to affect the way the user control works when running, but I can no longer see canvas when writing my XAML. (IE. the XAML won't render in the canvas area) I am pretty sure I have the dependency properties written correctly, but I thought I'd throw it out here to see if I am missing something or if there is a way to disable this error check.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top