FukYouAll
FukYouAll

Reputation: 111

XAML designer can't recognize other control properties (VS 2015)

I've recently installed Visual Studio 2015 Community, and I have a big WPF project initially developed in Visual Studio 2010, then, continued in Visual Studio 2012 Ultimate. The problem is that in this project I have some controls with properties set like that:

    private string _Header = "";
    public string TextHeader
    {
        get { return _Header; }
        set
        {
            _Header = value;
            if (_Header == string.Empty)
            {
                lTitle.Visibility = Visibility.Hidden;
                iSeparator.Visibility = Visibility.Hidden;
            }
            else
            {
                lTitle.Content = _Header;
                lTitle.Visibility = Visibility.Visible;
                iSeparator.Visibility = Visibility.Visible;
            }
        }
    }

I had no problems in the XAML designer in VS 2012, now, in this version of Visual Studio (2015), I'm unable to use the designer, it throws an error "Can't recognize or can't access the member "TextHeader"".

I don't have debug problems, the application runs with no problems, no exceptions and no problems in the controls that use these properties, and I think that is a problem with the XAML designer.

enter image description here

My project Framework version is 3.5 and target platform is x64.

Upvotes: 1

Views: 582

Answers (1)

keymusicman
keymusicman

Reputation: 1291

Properties that you want to set via XAML should be registered first. So, in your case code should be:

public static readonly DependencyProperty TextHeaderProperty = DependencyProperty.Register("TextHeader", typeof(string), typeof(StyledPanel))

public string TextHeader
{
    get { return (string)GetValue(TextHeaderProperty); }
    set { SetValue(TextHeaderProperty, value); }
}

This article explains DependencyProperties very well.

Note that after this changes you should rebuild your application.

Edit

Callback:

    public static readonly DependencyProperty TextHeaderProperty = DependencyProperty.Register(
        "TextHeader", 
        typeof(string), 
        typeof(StyledPanel), 
        new PropertyMetadata(TextHeaderPropertyChanged));

    private static void TextHeaderPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
    {
        var instance = sender as StyledPanel;
        if (String.IsNullOrEmpty(instance.TextHeader))
        {
            instance.lTitle.Visibility = Visibility.Hidden;
            instance.iSeparator.Visibility = Visibility.Hidden;
        }
        else
        {
            instance.lTitle.Content = _Header;
            instance.lTitle.Visibility = Visibility.Visible;
            instance.iSeparator.Visibility = Visibility.Visible;
        }
    }

Hope, it helps

Upvotes: 1

Related Questions