attachedproperties

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

What does InitializeComponent() do, and how does it work? (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 AttachedProperties. ...

PreviewCanExecuteEvent not executed

Hi folks I have a problem with my WPF program. I'm trying to create an object that will add handlers to all controls in the same scope. The following line does not work. The event is not handled. element.AddHandler(CommandManager.PreviewCanExecuteEvent, new CanExecuteRoutedEventHandler(scope.CanExecutedHandler), true); I also have ...

How to I access an attached property in code behind?

I have a rectangle in my XAML and want to change it's "Canvas.Left" property in code behind: <UserControl x:Class="Second90.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="400" Height="300" KeyDown="txt_KeyDown"> <Canvas> <Rec...

Add DataBinding for attached Property per Code Behind

I want to add a DataBinding per Codebehind for a attached Property and want to show the Canvas .Leftproperty in a textbox. How do I add this property? ...

Updating Custom Attached Property in Style Trigger with Setter

Hi All, 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 = DependencyProperty.RegisterAttached( "Something", typeof(int), typeof(Wind...

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 for the Behavior's Command always winds up being null. When used on the buttons it works ...

How do I make an AttachedProperty the target of a MultiBinding?

I've been working with the WPF DataGrid and trying to centralize my cell style. During this refactor, I came across a need for my cell style to know validation logic that is different for each column. I decided to provide an attached property on my column object, which would contain the result of my validation logic (with the logic being...

RegisterAttached String PropertyName causing AttachedProperty to not fire

I've run into an odd problem with attached properties where when I assign the property name in the call to RegisterAttached and name properly for the name of the attached property (say TranslateProperty and "Translate") the code for the attached property implementation doesn't fire. Just doesn't get called. If I change the string name to...

Silverlight 3: Expose Validation.GetHasError on custom control

I have written a custom UserControl that is embedded into another UserControl. Something like the simple diagram below. UserControl_A UserControl_B TextBox_1 CheckBox_1 Button_Save In UserControl-B the validation is working reasonably well but I want to check for errors in the logic of UserControl-A ( OnSaveClick event of t...

WPF does not seem to find a custom attached property

I am trying to bind a property (Button.Background) to a property on my custom attached property. In a C# file I have public static class Square { public static readonly DependencyProperty PlayerProperty = DependencyProperty.RegisterAttached("Player", typeof(Player), typeof(UIElement), new FrameworkPropertyMetada...

Where to put the XML documentation comments for an attached property ?

Hi all, Assuming I have an attached property defined like that : public static string GetMyProperty(DependencyObject obj) { return (string)obj.GetValue(MyPropertyProperty); } public static void SetMyProperty(DependencyObject obj, string value) { obj.SetValue(MyPropertyProperty, value); } //...

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

WPF - Handling custom attached events on custom controls

I have a routed event declared as such (names have been changed to protect the innocent): public class DragHelper : DependencyObject { public static readonly RoutedEvent DragCompleteEvent = EventManager.RegisterRoutedEvent( "DragComplete", RoutingStrategy.Bubble, typeof(DragRoutedEventHandler), typeof...

I've created an Attached Property, now how do I use it?

I'm trying to determine if Attached Behaviors are something we need in building controls for the forms in our application. Hence, I not only want to know how to create Attached Behaviors but want to see real instances in which they are used to solve problems. I used this MSDN article to create a UserControl with an attached property in ...

How to serialize attached properties

Hello everyone, I am writing .NET3.5, WPF application using Composite Application Library. Application is divided into several modules. In infrastructure module I have defined NetworkNode object. The Network module manages a collection of NetworkNodes and uses XmlSerializer to store/load this collection. So far everythings works. But...

Silverlight DataGridColumn AttachedProperties

I am attempting to create an AttachedProperty for a DataGridColumn within Silverlight 3.0 and I am having some issues. Here is the AttachedProperty: public class DataGridColumnHelper { public static readonly DependencyProperty HeaderProperty = DependencyProperty.RegisterAttached("Header", typeof(string), typeof(DataGridColu...

Bind to attached property in ControlTemplate - Silverlight

I have this style: <Style x:Key="ButtonStyle" TargetType="Button"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Grid> <StackPanel> <Image Source="{Binding Path=local:AttachedProperties.Im...

What's wrong with my datatrigger binding?

I have created an attached property to extend a Button class with additional state: <Button v:ExtensionHelper.OperationMode="{Binding MyObject.OperationMode}" Command="{Binding MyObject.Select}" Style="{StaticResource operationModeControlTemplateStyle}" /> Then I want to acces this value in the controltemplate using Datatriggers like ...

binding element focus with an attached property?

Hi guys, I'm trying to bind focus for my control to a property on the view model, like this: public class Focus { public static readonly DependencyProperty HasFocusProperty = DependencyProperty.RegisterAttached("HasFocus", t...

Garbage Collection when Attached dependencyobject is destroyed \ disconnected

Hi Guys, When we use any attached property against any dependency object, I thunk it actually maps the property and the value with the dependency object. E.g. <DockPanel><TextBlock x:Name="MyText" DockPanel.Dock="Top"/></DockPanel> Here value "Top" is mapped with DockPanels DockProperty via the dependency object textblock "MyText" ...