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
3
votes
2 answers

Attached Collection Items Losing Data Context

I created an attached property, AttachedBehaviorsManager.Behaviors that is to be used as an MVVM helper class that ties events to commands. The property is of type BehaviorCollection (a wrapper for ObservableCollection). My issue is that the Binding…
Jason
3
votes
1 answer

Visual Studio Designer Attached Properties

I am using attached properties to allow some design-time behaviour in the Visual Studio WPF designer i.e. design-time view-model data. The issue I'm having is that when attached property events fire at design-time for my UserControl, the type of the…
Tim Lloyd
  • 37,954
  • 10
  • 100
  • 130
3
votes
2 answers

WPF/Attached Properties - Please explain why this works

Please help me understand where the value "ABC" gets stored. When I run memory profilers I don't see any instance of MyClass, and in fact the binding works and the GroupBox.Header gets the value ABC... Thanks for your help.
Gus Cavalcanti
  • 10,527
  • 23
  • 71
  • 104
3
votes
1 answer

Why does DataContext fail to inherit on objects constructed as attached properties?

While constructing an object in xaml, the DataContext seems to resolve properly most of the time, but constructing that same object directly in the scope of an Attached Property seems to block DataContext inheritance. In this, there are several…
etberg
  • 111
  • 1
  • 7
3
votes
1 answer

Unity in attached properties

I need to create an attached property which communicates with some service inside it's PropertyChanged event handler. E. g. private static void IsRegisteredPropertyChanged(DependencyObject target, …
3
votes
0 answers

How to remove attached property when WPF control is unloaded?

I've one AttachedProperty, which is bound to a singleton. The attached property: public static bool? GetIsFocused(DependencyObject obj) { return (bool?)obj.GetValue(IsFocusedProperty); } public static void SetIsFocused(DependencyObject obj,…
J4N
  • 19,480
  • 39
  • 187
  • 340
3
votes
1 answer

QT QML Accessing Attached Property From Another QML Object

main.qml: import QtQuick 2.11 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.3 ApplicationWindow { id: window x: 200 y: 200 visible: true Component { id: firstViewComponent FirstView { id:…
Colin
  • 2,089
  • 25
  • 34
3
votes
5 answers

Why does WPF use attached properties for things like positioning in a grid?

Why do we need "attached properties"? The concept of it bugs me a bit, since you can conceivably set values of properties that don't even exist on a particular DependencyObject (and they will just be silently ignored). It almost seems like a…
J Cooper
  • 16,891
  • 12
  • 65
  • 110
3
votes
2 answers

How do I get the X,Y position of a UserControl within a Canvas?

I have a simple UserControl implemented as below - which I place in a Canvas. I move it using Multi-touch and I want to be able to read its new X,Y postion using procedural C# code. Ideally I would like to have X and Y as two properties or as a…
AlanW
  • 53
  • 1
  • 5
3
votes
1 answer

Collection-Type Attached Properties

I would like to extend FrameworkElement elements like the Button class by collection-type attached property that collect DependencyObjects. The difficulty is that the bindings to the collection items do not work: No debug nor runtime error shows up…
Chris
  • 2,071
  • 4
  • 14
  • 22
3
votes
1 answer

Get attached property instance from dependency property change callback

Is there anyway of getting the instance of an attached property from a property change callback sitting on the attached property type? In other words, if you have: public class MyAttachedPropertyClass { public static readonly…
devdigital
  • 34,151
  • 9
  • 98
  • 120
3
votes
1 answer

Wpf styles and attached properties

I've been playing with behaviors and I came across a interesting issue. Here is my behavior: public class AddNewBehavior : BaseBehavior { public static readonly DependencyProperty IsEnabledProperty =…
Calin
  • 6,661
  • 7
  • 49
  • 80
3
votes
2 answers

WPF TextBox lostfocus as attached property

I have a Grid with many TextBoxes and I want to call NotifyPropertyChanged() method to update some other controls everytime one of these TextBox-es changed the value = lost the focus (I don't want to use PropertyChanged as…
theSpyCry
  • 12,073
  • 28
  • 96
  • 152
3
votes
1 answer

Use Dependency Property to pass a callback method

I am using the Jarloo's calendar control in order to display a calendar in my WPF software. For my needs, I added that each day contains a list of items, lets say List Items. The Jarloo calendar is a second project within my main visual studio…
dotixx
  • 1,490
  • 12
  • 23
3
votes
1 answer

Cannot convert the value in attribute '[attr]' to object of type 'System.Windows.TemplateBindingExtension'

I get this error when I define my attached dependency properties in a class outside the class hierarchy and set the owner to a common parent class. Attached dependency property in WindowBase class (outside class hierarchy => generated error): public…
Krimson
  • 762
  • 6
  • 25