attached-properties

Set the binding value directly

你离开我真会死。 提交于 2019-12-30 04:40:13
问题 Is it possible to set the value behind a two-way binding directly, without knowing the bound property? I have an attached property that is bound to a property like this: <Element my:Utils.MyProperty="{Binding Something}" /> Now I want to change the value that is effectively stored in Something from the perspective of the attached property. So I cannot access the bound property directly, but only have references to the DependencyObject (i.e. the Element instance) and the DependencyProperty

What's the difference between a dependency property and an attached property in WPF?

妖精的绣舞 提交于 2019-12-27 12:14:45
问题 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? 回答1: Attached properties are a type of dependency property. The difference is in how they're used. With an attached property, the property is defined on a class that isn't the same class for which it's being used. This is usually used for layout. Good examples are Panel.ZIndex or Grid.Row - you apply this to a control (ie:

Change Source of Binding for attached property

两盒软妹~` 提交于 2019-12-25 08:08:00
问题 If I use binding extension in attached property <TextBlock local:MyBehavior.View="{Binding A}" /> <!-- or B --> How can set value of A (or B ) property of ViewModel from that attached behavior? I do not understand: Which type to use for attached property? Binding ? BindingBase ? BindingExpressionBase ? object ? Shall I set the value immediately? Shall I wait for some event? Shall I use another dependency property to set it's value, then bind to SomeProperty and let binding do the job once

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

安稳与你 提交于 2019-12-24 09:35:41
问题 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 sample code I used: public static readonly DependencyProperty IsEigenaarProperty = DependencyProperty.RegisterAttached( "Eigenaar", typeof(clsPersoon), typeof(UIElement), new

How can an attached behavior be added to a CollectionViewSource?

最后都变了- 提交于 2019-12-22 11:23:36
问题 I am trying to add an attached behavior to a CollectionViewSource so that I can provide a filter Predicate property on my view-model in XAML. The XAML looks like the following: <DataGrid ItemsSource="{Binding}"> <DataGrid.DataContext> <CollectionViewSource Source="{Binding Path=Items}" acb:CollectionViewSourceItemFilter.ItemFilter="{Binding Path=ItemFilter}" /> </DataGrid.DataContext> </DataGrid> However, I am getting an error: A 'Binding' cannot be set on the 'SetItemFilter' property of type

WPF: In an attached property, how to wait until visual tree loaded properly?

非 Y 不嫁゛ 提交于 2019-12-22 09:26:04
问题 I have an Attached Property in a WPF app. The code below is inside the OnLoad event, but it doesn't work unless I add a hacky 500 millisecond delay in. Is there some way to avoid this delay, and detect when the visual tree has been loaded? private static void FrameworkElement_Loaded(object sender, RoutedEventArgs e) { // ... snip... Window window = GetParentWindow(dependencyObject); // Without this delay, changing properties does nothing. Task task = Task.Run( async () => { { // Without this

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

半腔热情 提交于 2019-12-20 20:32:56
问题 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 attached behaviors. Are there any strategies available to reduce the amount of boilerplate code I have to write? Thanks! 回答1: Personally, I like Josh Smith's MVVM Foundation library. He uses a class called RelayCommand there, but it sounds pretty similar

Silverlight 4 Default Button Service

限于喜欢 提交于 2019-12-20 10:54:34
问题 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 attached behaviours in SL4? Is there any other way to achieve default button behaviour in SL4 with the new classes that are available? Thanks, Mark 回答1: I

Binding to attached property

夙愿已清 提交于 2019-12-20 01:09:37
问题 I'm trying to bind from Button's ContentTemplate to attached property. I read all the answers for question similar to "binding to attached property" but I had no luck resolving the problem. Please note that example presented here is a dumbed down version of my problem to avoid cluttering the problem with business code. So, I do have static class with attached property: using System.Windows; namespace AttachedPropertyTest { public static class Extender { public static readonly

Difference between Attached and non-Attached Dependency Properties in Silverlight

回眸只為那壹抹淺笑 提交于 2019-12-18 04:36:15
问题 Okay Stackers, I've spent a good couple of hours on this question, and I want to know if anybody has a definitive answer. For all the research I've done, I can't find ANY difference between .Register and .RegisterAttached in Silverlight . Now, before you jump the gun and tell me that .RegisterAttached is used for attaching a DP to another class, try implementing an Attached Dependency Property using DependencyProperty.Register() . I have found not a single difference, and so I am at a loss as