Live Chat Icon For mobile
Live Chat Icon

What are Attached Properties and how to register it?

Platform: WPF| Category: Dependency Property

An ‘attached’ property is a concept defined by Extensible Application Markup Language (XAML). It is intended to be used as a type of global property that can be set on any object. In Windows Presentation Foundation (WPF), attached properties are typically defined as specialized forms of dependency properties that do not have the conventional ‘wrapper’ property.

This example shows how to ’register’ an attached property and provide public accessors so that you can use the property in both Extensible Application Markup Language (XAML) and code. Attached properties are a syntax concept defined by Extensible Application Markup Language (XAML). Most of the attached properties for WPF types are also implemented as dependency properties. You can use dependency properties on any ’DependencyObject’ types.

[C#]
public static readonly DependencyProperty IsBubbleSourceProperty = DependencyProperty.RegisterAttached(
  'IsBubbleSource',
  typeof(Boolean),
  typeof(AquariumObject),
  new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender)
);
public static void SetIsBubbleSource(UIElement element, Boolean value)
{
  element.SetValue(IsBubbleSourceProperty, value);
}
public static Boolean GetIsBubbleSource(UIElement element)
{
  return (Boolean)element.GetValue(IsBubbleSourceProperty);
}

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.