I am trying to use a binding with an attached property. But he cannot make it work.
public class Attached { public static DependencyProperty TestProperty = DependencyProperty.RegisterAttached("TestProperty", typeof(bool), typeof(Attached), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Inherits)); public static bool GetTest(DependencyObject obj) { return (bool)obj.GetValue(TestProperty); } public static void SetTest(DependencyObject obj, bool value) { obj.SetValue(TestProperty, value); } }
XAML Code:
<Window ...> <StackPanel local:Attached.Test="true" x:Name="f"> <CheckBox local:Attached.Test="true" IsChecked="{Binding (local:Attached.Test), Mode=TwoWay, RelativeSource={RelativeSource Self}}" /> <CheckBox local:Attached.Test="true" IsChecked="{Binding (local:Attached.Test), Mode=TwoWay}" /> </StackPanel> </Window>
And the binding error:
System.Windows.Data Error: 40 : BindingExpression path error: '(local:Attached.Test)' property not found on 'object' ''StackPanel' (Name='f')'. BindingExpression:Path=(local:Attached.Test); DataItem='StackPanel' (Name='f'); target element is 'CheckBox' (Name=''); target property is 'IsChecked' (type 'Nullable`1')
wpf binding xaml attached-properties
SACO Apr 29 '11 at 12:45 2011-04-29 12:45
source share