WPF user control property appears not empty in Visual Studio XAML Properties toolbar

Fernando 0 Reputation points
2023-03-09T15:38:56.9366667+00:00

Hello

I'm creating a WPF custom Button Control inheriting from System.Windows.Controls.Button.

using System.ComponentModel;
using System.Windows.Controls;

namespace BMCustomer
{
    public class MyButton : Button
    {
        [Category("MyCategory")]
        [Description("Description for MyText property")]
        //[DefaultValue(null)]
        [DefaultValue("")]
        public string MyText { get; set; }

        //public string MyText
        //{
        //    get { return (string)GetValue(MyTextProperty); }
        //    set { SetValue(MyTextProperty, value); }
        //}

        //public static readonly System.Windows.DependencyProperty MyTextProperty =
        //        System.Windows.DependencyProperty.Register("MyText", typeof(string), typeof(MyButton),
        //        new System.Windows.FrameworkPropertyMetadata(null));

    }
}

When I use MyButton in an XAML and select the Control, the Properties toolbox displays "MyText" property as "MyText" instead of empty. But ContentStringFormat, that is also a string property of the inherited Button, is displayed as empty. See below the image of Visual Studio.

User's image

I tried a lot of combinations for this property to be displayed empty with no success: making a DependecyProperty, using DefaultAttribute ...

How can I make this property to be displayed blank when no used?

Thank you in advance

Developer technologies | Windows Presentation Foundation
Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other
A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.