attachedproperties

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

Attached Property: 'System.TypeInitializationException' when setting default value

I want to set a default value of my Attached Property, but when I do I get: A first chance exception of type 'System.ArgumentException' occurred in WindowsBase.dll A first chance exception of type 'System.TypeInitializationException' occurred in Oef_AttDepProp.exe Without the default value, things work fine. This is some sampl...

Creating a Window.Title Attached Property

I have a Window shell that is basically: <Window> <ContentPresenter Content="{Binding}" /> </Window> Injected into the ContentPresenter at run-time are UserControls. What I want to be able to do is write: <UserControl Window.Title="The title for my window"> [...] </UserControl> So that the Window title is updated using the User...

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

WPF Designer - Update attached property when control is added/dragged

I have made a custom panel which has attached properties for each childs position (Left, Top). When I drag a control from the toolbox onto my custom panel, it draws at 0,0 as these are the default values for the attached properties. If I try and move the control around the panel it just stays at 0,0 as moving in the designer does not upd...

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: <DataTemplate DataType="{x:Type TestApp:ButtonVM}"> <Button Grid.Column="{Binding GridColumn}" Grid.Row="{Binding GridRow}" Content="{Binding Path=Info}" /> </DataTemplate> The Cont...

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

Attached Property Changed Event?

Hello, ist there a way to get a change notification if an attached property changed? A simple example is a Canvas with a Rectangle in it. The position of the Rectange is set by using the DepenendyProperties Canvas.Top and Canvas.Left. I'm using an Adorner to move the Rectangle around by changing the Canvas.Top and Canvas.Left. <Canva...

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

MVVM- How can I bind to a property, which is not a DependancyProperty?

I have found this question http://stackoverflow.com/questions/2245928/mvvm-and-the-textboxs-selectedtext-property. However, I am having trouble getting the solution given to work. This is my non-working code, in which I am trying to display the first textbox's selected text in the second textbox. View: SelectedText and Text are just st...

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

Hi, 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 static readonly DependencyProperty AreaColorProperty = DependencyProperty.Register...

Silverlight 4 Default Button Service

For a few months I have been successfully using David Justices Default Button example in my SL 3 app. This approach is based on an attached property. After upgrading to SL4, the approach no longer works, and I get a XAML exception: "Unknown parser error: Scanner 2148474880" Has anyone succesfully used this (or any other) default button...

How are attached properties useful in LINQ?

I got this question during an interview in the past and never really dug into in, but I've put some thought into it lately and I can't come up with a good answer. When I think of attached properties my mind goes straight to UI related concepts - what benefits could be had in using attached properties with LINQ? I'm starting to think th...

Can't use attached property on combobox inside hierarchical datatemplate WPF

I'm hoping to use an attached property to assign a command to the selection changed event of a combobox that is embedded inside a treeview. I'm attempting to set the attached property inside the hierchical data template for the tree but the command is not set and does not fire when the item in the combobox is changed. I've found that ...

Silverlight Required TextBox Attached Property

I have a need to create an attached property for a TextBox, that enforces a rule that content is required. NOTE: Unfortunately I am not able to use data annotations, or SL4 validation frameworks. The textboxes are displayed within the context of a View. The View is reused in many places. When tabbing / clicking between TextBoxes within...

Displaying FontFamily in Combobox

Hi. My goal is to manipulate the text-styles of my application via DependencyProperties. I got a diagram in which the texts are to be manipulated in size, fontfamily, color, etc. So I'd like to use an interface similar to a rich text editor like Word. I'm using this code in my TextStyleVM http://shevaspace.blogspot.com/2006/12/i-have-s...

Render a custom attached property value

I need to do this in XAML : <Grid x:Name="layoutRoot"> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <SomeUserControl Grid.Row="0" /> <ui:AdditionalView.UseCase1> <ContentControl> <TextBlock>aaa</TextBlock> </ContentC...

Adding Enumeration Value to Silverlight Attribute/Property

In the <ImageBrush/> element, there are AlignmentX and AlignmentY attributes with values Left/Center/Right and Top/Center/Bottom, respectively. What I'm wanting to do is set my own value in, for example, AlignmentX either as a value or as another enumeration like AlignmentX="HalfCenter" where HalfLeft equals my own value (halfway betwee...

How to define 'Attached property' as 'SelectedValuePath' in ComboBox?

Hi, I have a problem with binding in ComboBox. I'd like to bind ComboBox items to ListView columns and as a selected value return value of attached property defined on the selected column. In example bellow you can see working sample that displays width of selected column. If you try to change SelectedValuePath in ComboBox into (loc:Sam...