Questions tagged [attachedbehaviors]

142 questions
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
36
votes
3 answers

How do you handle a ComboBox SelectionChanged in MVVM?

For those doing pure MVVM, how do you handle a ComboBox SelectionChanged event without reverting to code behind? I tried e.g. AttachedBehaviors but Event="SelectedChanged" is not supported:
Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047
20
votes
2 answers

Event unsubscription via anonymous delegate

I am using Resharper 5.1 code analysis many a times i get a comment from resharper as "Event unsubscription via anonymous delegate" #Part of Code if (((bool)e.NewValue)) { listView.PreviewTextInput += (o,args) => …
Ankesh
  • 4,847
  • 4
  • 38
  • 76
13
votes
2 answers

How can I fix the DependencyPropertyDescriptor AddValueChanged Memory Leak on AttachedBehavior?

I know I need to call RemoveValueChanged, but I have not been able to find a reliable place to call this. I'm learning that there probably isn't one. I looks like I need to find a different way to monitor the change then adding a handler using…
scuba88
  • 458
  • 2
  • 4
  • 13
12
votes
1 answer

Is there a safe way to detach/unload behaviors without side effects?

In WPF and WinRT it is well known that behaviors do not call their Detach method reliably. The only way to avoid a memory leak is to subscribe to the Unloaded event of the AssociatedObject and unhook all events (example). So far it works. But I…
Amenti
  • 1,511
  • 1
  • 13
  • 29
11
votes
3 answers

Reducing boilerplate code in MVVM WPF app for attached properties, commands, etc?

I'm working on a WPF MVVM application. The thing that I'm noticing is that I have to write an inordinate amount of boilerplate code just to declare commands (through DelegateCommands from the WPF Team's MVVM Toolkit), attached properties and…
djcouchycouch
  • 12,724
  • 13
  • 69
  • 108
8
votes
1 answer

option is not coming for applying beahviour

I have been trying to implement a behavior on a wpf window therefore I have added reference to System.Winodws.Interactivity in my current solution and then wrote the desired behavior. but in order to apply this behavior, I have to write something…
Yogesh
  • 3,044
  • 8
  • 33
  • 60
7
votes
2 answers

Blend Behaviours - can you bind to their properties?

I am currently migrating a number of attached behaviours I have created to Blend Behaviours so that they support drag and drop within Expression Blend. I have noticed that authors of Blend behaviours tend to define the behaviour properties as…
ColinE
  • 68,894
  • 15
  • 164
  • 232
7
votes
2 answers

unit test an attached behavior wpf

I am still grokking attached behaviors in general, and am at a loss to see how to write a unit test for one. I pasted some code below from Sacha Barber's Cinch framework that allows a window to be closed via attached behavior. Can somewone show me…
Berryl
  • 12,471
  • 22
  • 98
  • 182
6
votes
2 answers

DependencyProperty of Type Delegate

I have created an attached behavior that is used to execute a Delegate of type Func when the behavior is invoked. Below is the dependancy property definition. public static readonly DependencyProperty SendToDetailBehaviorProperty =…
6
votes
2 answers

How to create an Attached Behavior for automatic scrolling of a FlowDocumentScrollViewer

My goal is to create a reusable Attached Behavior for a FlowDocumentScrollViewer, so that the viewer automaticly scrolls to the end whenever the FlowDocument has been updated (appended). Problems so far: OnEnabledChanged gets called before the…
chilltemp
  • 8,854
  • 8
  • 41
  • 46
6
votes
1 answer

Attach behaviour to all TextBoxes in Silverlight

Is it possible to attach behavior to all TextBoxes in Silverlight application? I need to add simple functionality to all text boxes. (select all text on focus event) void Target_GotFocus(object sender, System.Windows.RoutedEventArgs e) { …
barbarian
  • 1,559
  • 6
  • 20
  • 26
5
votes
1 answer

Attached behaviors and styles

I use an attached behavior that allows a DoubleClick event to be wired to a command in a view model, as in the binding below:
Berryl
  • 12,471
  • 22
  • 98
  • 182
5
votes
2 answers

Automatically calling OnDetaching() for Silverlight Behaviors

I am using several Blend behaviors and triggers on a silverlight control. I am wondering if there is any mechanism for automatically detaching or ensuring that OnDetaching() is called for a behavior or trigger when the control is no longer being…
5
votes
2 answers

Custom attached events in WPF

I might be getting the terminology wrong here, but I think I'm trying to create an attached event. In the Surface SDK, you can do things like:
Josh Santangelo
  • 936
  • 4
  • 11
  • 16
1
2 3
9 10