attachedbehaviors

How to use AttachedCommandBehavior in a new project?

I've downloaded this AttachedCommandProject and ran it and it works well, enables me to e.g. put a MouseDown command on a Border element and handle that with a command in my ViewModel. Now I would like to add this AttachedCommand functionality to my MVVM Visual Studio Template. I copied all the necessary files into the my Commands fold...

How can I attach two attached behaviors to one XAML element?

I've implemented the attached command behavior pattern found here and it works well to allow e.g. a Border to have a left- or right-click event that fires in the ViewModel: XAML: <Border Background="Yellow" Width="350" Margin="0,0,10,0" Height="35" CornerRadius="2" c:CommandBehavior.Event="MouseLeftButtonDown" c:Comman...

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: <ComboBox> <ComboBoxItem Content="Test1"> <c:CommandBehaviorCollection.Behaviors> <c:BehaviorBinding Event="SelectionChange...

WPF - Random hanging with file browser attached behaviour.

Hi, I have an attached behavior defined thusly,.. public static class FileBrowserBehaviour { public static bool GetBrowsesOnClick(DependencyObject obj) { return (bool)obj.GetValue(BrowsesOnClickProperty); } public static void SetBrowsesOnClick(DependencyObject obj, bool value) { obj.SetValue(BrowsesOnClickProperty, valu...

Mutually Exclusive SelectedItem

I have a treeview and a datagrid. When I select an item on my datagrid, I want to set the selectedItem on my treeview to null, and when I select an item on my treeview I want to set the selectedItem on my datagrid to null. I'd also like to have a central FocussedItem notification property that both the treeview and datagrid update with...

Attached Property and Binding

I'm creating an attached behavior in order to set a regular property of a class: public class LookupHelper { public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.RegisterAttached("ItemsSource", typeof(object), typeof(LookupHelper), new UIPropertyMetadata(null, OnItemsSourceChanged)); private static...

How to expose xaml properties?

I created a ComboBox subclass and added my functionality. Now I want to expose external properties of the TextBox for example: <a:MyComboBox SpellCheck.IsEnabled="True" TextBox.SelectedText="{Binding X}" /> Is this possible, I maybe didn't choose the wrong particular property but I guess you understand what I mean. Is this possible?...

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 an example unit test for it? Thanks! Berryl #region Close /// <summary>Dependen...

Silverlight MouseDragElementBehavior. How to rearrange items after drag and drop?

I have stack panel with custom controls in it. User can add or remove the items. I have attached MouseDragElementBehavior to each item. So now user can move them within the stack panel. However the items now are arranged on arbitrary manner. Is a mess really. They stay where the user left them. What I need now is to make them to be st...

Silverlight ComboBox Attached Behavior

I am trying to create an attached behavior that can be applied to a Silverlight ComboBox. My behavior is this: using System.Windows.Controls; using System.Windows; using System.Windows.Controls.Primitives; namespace AttachedBehaviours { public class ConfirmChangeBehaviour { public static bool GetConfirmChange(Selecto...

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? ...

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 used (i.e. removed from the visual tree). My problem is that there is a managed memory leak ...

Expectations when disabling a WCF Behaviour Extension

Straw poll 'cause we can't decide internally: If I'm implementing a BehaviorExtensionElement which is possible to disable through configuration is it reasonable/possible for CreateBehavior() to return null or should it always return a zombie behaviour object in some kind of disabled state instead? (Don't ask why we have disable instea...

WPF - attached behavior to capture MouseEnter on Image in TreeviewITem

Hi! Could I have, please, a little code-sample of WPF "attached behavior"? I explain my problem: I've done my TreeView all with XAML but now I'd like to manage an event with code-behind. The HierarchicalDataTemplate contains an Image. I need to capture the events MouseEnter / MouseLeave on the Image. I'd like to do this with "attache...

WPF - Styles with Custom Properties

Hello. I'm developing a document number checking on my application and I wrote an attached behavior to textbox to check the text. Here's the behavior code: public class CPFTextBehavior : Behavior<TextBox> { static readonly DependencyPropertyKey IsCPFPropertyKey = DependencyProperty.RegisterAttachedReadOnly("IsCP...

WPF - Dependency Properties Error

Hello again. I'm working on a WPF project, and my intention is to make two specific RadioButtons alter properties of another specified Component. But for now, i'm just trying to store a String inside the RadioButton. For that, I've created a behavior class: public class AdjustBehavior : Behavior<RadioButton> { With this property...

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 visual tree is completed, and thus doesn't find the ScrollViewer I don't know how to attac...

Binding Attached Behaviour from code

I am using a custom default button attached behaviour (as defined here: http://stackoverflow.com/questions/2683891). I am able to bind this successfully in XAML, but in a nested user control, in code behind the following does not work: public partial class MyNestedUserContol{ /// a DP for storing the name of the default button, used i...

DependencyProperty of Type Delegate

Hello, I have created an attached behavior that is used to execute a Delegate of type Func<bool> when the behavior is invoked. Below is the dependancy property definition. public static readonly DependencyProperty SendToDetailBehaviorProperty = DependencyProperty.RegisterAttached("SendToDetailBehavior", typeof(Func<bool>), typeof(ListD...

WPF - Resizing chromeless windows using attached behaviors,..Any suggestions?

Who fancies a challenge? I'm currently working on the ControlTemplate for a chromeless Window which will be a part of a reusable theme assembly. I want the behaviors for moving, closing, minimizing and restoring to be implicit so I've written attached behaviors for this functionality which I've then included in the template. Now,..I'v...