Questions tagged [attached-properties]

In Windows Presentation Foundation (WPF), attached properties are a specialized form of dependency property that does not have the conventional property "wrapper".

An attached property is intended to be used as a type of global property that is settable on any object. It allows different child elements to specify unique values for a property that is actually defined in a parent element (Grid.Row and Grid.Column are an example of frequenly used attached dependency properties).

General information: Attached Properties Overview

458 questions
181
votes
2 answers

What does InitializeComponent() do, and how does it work in WPF?

What does InitializeComponent() do, and how does it work in WPF? In general first, but I would especially be interested to know the gory details of order of construction, and what happens when there are Attached Properties.
Tim Lovell-Smith
  • 15,310
  • 14
  • 76
  • 93
102
votes
3 answers

Change Canvas.Left property in code behind?

I have a rectangle in my XAML and want to change its Canvas.Left property in code behind:
Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047
98
votes
5 answers

What's the difference between a dependency property and an attached property in WPF?

What's the difference between a (custom) dependency property and an attached property in WPF? What are the uses for each? How do the implementations typically differ?
kenwarner
  • 28,650
  • 28
  • 130
  • 173
87
votes
2 answers

When should I use FrameworkPropertyMetadata or UIPropertyMetadata over plain PropertyMetadata?

When looking at sample attached properties and behaviors, I've seen a mishmash of uses of FrameworkPropertyMetadata, UIPropertyMetadata and PropertyMetadata. Since they all form an inheritance hierarchy, how do I choose which one to use?
Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
86
votes
3 answers

WPF Attached Property Data Binding

I try to use binding with an attached property. But can't get it working. public class Attached { public static DependencyProperty TestProperty = DependencyProperty.RegisterAttached("TestProperty", typeof(bool), typeof(Attached), …
Daniel Bişar
  • 2,663
  • 7
  • 32
  • 54
38
votes
1 answer

How to use Attached property within a style?

I have created an Image within a ButtonStyle. Now I have created an Attached Property so that I can set the Source for that Image. Should be straight forward but I am stuck with it. This is my shortened ButtonStyle:
Houman
  • 64,245
  • 87
  • 278
  • 460
29
votes
2 answers

Template Binding with Attached Properties

I have a standard style for my buttons but I want certain parts of the style to be configurable. e.g. I have a border appear when MouseOver is triggered for the button and I want the border colour to be configurable. Following this article:…
thudbutt
  • 1,481
  • 1
  • 19
  • 32
27
votes
3 answers

How exactly do Attached Properties work in WPF?

I'm a bit mystified as to how Attached Properties actually convey their values to either parent or child elements. TextElement.FontFamily causes child elements to inherit the value assigned to that property (a seemingly downstream operation, parent…
Mark Carpenter
  • 17,445
  • 22
  • 96
  • 149
19
votes
1 answer

Bind Grid.Row / Grid.Column inside a DataTemplate

Hope this is not a dupe. I would like to be able to do the following in XAML:
19
votes
1 answer

C# WPF Attached Properties - Error: "The property does not exist in XML namespace"

I need to create a new property to existing WPF controls (Groupbox, textbox, checkbox, etc), one that will storage its acess Level, therefore I've found out Attached Properties. I used as example this site…
19
votes
1 answer

Attached property of type list

I want to create an attached property that can be used with this syntax: This is my…
HappyNomad
  • 4,458
  • 4
  • 36
  • 55
14
votes
3 answers

using attached events with caliburn micro Message.Attach

I'm trying to use caliburn micro message to trigger an attached event that I created: public static class DataChanging { public delegate void DataChangingEventHandler(object sender, DataChangingEventArgs e); public static readonly…
Clueless
  • 1,190
  • 2
  • 14
  • 30
13
votes
5 answers

Difference between Attached and non-Attached Dependency Properties in Silverlight

Okay Stackers, I've spent a good couple of hours on this question, and I want to know if anybody has a definitive answer. For all the research I've done, I can't find ANY difference between .Register and .RegisterAttached in Silverlight. Now,…
12
votes
1 answer

Updating Custom Attached Property in Style Trigger with Setter

I was trying out attached properties and style triggers hoping to learn more about it. I wrote a very simple WPF windows app with an attached property: public static readonly DependencyProperty SomethingProperty = …
oscarkuo
  • 10,431
  • 6
  • 49
  • 62
12
votes
1 answer

How do I handle Canvas.Top change event in WPF?

I have an element positioned on Canvas using attached properties Canvas.Top and Canvas.Left. Then using animations the element is moved to different set of coordinates, like this: DoubleAnimation left = new DoubleAnimation( oldLeft, newLeft…
zzandy
  • 2,263
  • 1
  • 23
  • 43
1
2 3
30 31