4

I want to mark any control with custom property. For example like "Obsolete".

And other requirement that I want microsoft visual studio and blend to ignore this property!

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

How can I mark with custom property my controls? And I need to be sure that if dll is missing visual studio and blend will ignore this property.

SingerOfTheFall
  • 29,228
  • 8
  • 68
  • 105

1 Answers1

1

The first part of your request can be done by using Dependency Properties or Attached Properties.

See the following sample code:

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 would need more clarification, like why would you want Visual Studio or Blend to ignore this property? Furthermore, what do you mean by 'if dll is missing visual studio and blend will ignore this property'? In order to improve this answer I would need some more detail from your side, otherwise it remains mainly guesswork.

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


Further References:

Community
  • 1
  • 1
pdvries
  • 1,372
  • 2
  • 9
  • 18