How to add custom ignored property in wpf

I want to mark any control with a custom property. For example, like "Deprecated."

And another requirement is that I want Microsoft Visual Studio and the mixture to ignore this property!

I noticed that blend uses mc:Ignorable="d" and adds the d:DesignerWidth property.

How can I tag my controls with a custom property? And I must be sure that if the dll is missing a visual studio and the mixture ignores this property.

+4
source share
1 answer

The first part of your query can be done using dependency properties or added properties.

See the following code example:

 public static readonly DependencyProperty ObsoleteAttached = DependencyProperty.RegisterAttached( "ObsoleteAttached", typeof(Boolean), typeof(UserControl1), new UIPropertyMetadata(false) ); public static Boolean GetObsoleteAttached(DependencyObject obj) { return (Boolean)obj.GetValue(ObsoleteAttached); } public static void SetObsoleteAttached(DependencyObject obj, Boolean value) { obj.SetValue(ObsoleteAttached, value); } public Boolean Obsolete { get { return (Boolean)this.GetValue(ObsoleteProperty); } set { this.SetValue(ObsoleteProperty, value); } } public static readonly DependencyProperty ObsoleteProperty = DependencyProperty.Register( "Obsolete", typeof(Boolean), typeof(UserControl1), new PropertyMetadata(false)); 

Your second part will need more clarification, for example, why do you want Visual Studio or Blend to ignore this property? Besides, what do you mean by "if the dll is missing a visual studio, and the blend ignores this property"? To improve this answer, I will need more detailed information on your part, otherwise it will be mainly guesswork.

You can download the full source code here . The application allows you to select various Image-resources, however, it was made to demonstrate the "requested" purpose.


Further links:

+1
source

Source: https://habr.com/ru/post/1435162/


All Articles