I am trying to set a WPF behavior property using a style like this:
<StackPanel> <CheckBox Name="IsFemaleChkBox" Content="Is Female ?" /> <TextBlock> <Hyperlink> <TextBlock Text="My Hyperlink"/> <Hyperlink.Style> <Style TargetType="Hyperlink"> <Setter Property="local:MyHyperLinkBehavior.Salutation" Value="Mr." /> <Style.Triggers> <DataTrigger Binding="{Binding IsChecked, ElementName=IsFemaleChkBox}" Value="True"> <Setter Property="local:MyHyperLinkBehavior.Salutation" Value="Miss" /> </DataTrigger> </Style.Triggers> </Style> </Hyperlink.Style> </Hyperlink> </TextBlock> </StackPanel>
And the code for the behavior class is this:
class MyHyperLinkBehavior : Behavior<Hyperlink> { protected override void OnAttached() { base.OnAttached(); AssociatedObject.Click += AssociatedObject_Click; } public static bool GetIsFemale(DependencyObject obj) { return (bool)obj.GetValue(IsFemaleProperty); } public static void SetIsFemale(DependencyObject obj, bool value) { obj.SetValue(IsFemaleProperty, value); }
I canβt understand why this is not working. Or is setting a behavior property using a style invalid at all? What will be the other way around if this is not true.
source share