AvaloniaUI / Avalonia.Xaml.Behaviors

Port of Windows UWP Xaml Behaviors for Avalonia Xaml.
MIT License
385 stars 46 forks source link

Binding to attached property exception #128

Closed Mochengvia closed 1 year ago

Mochengvia commented 1 year ago

I tried binding the DataTriggerBehavior's Binding property to the Button's i:VisualStateHelper.Background attached property, but I got an exception: System.ArgumentException: "Could not find binding source: either target or anchor must be an IStyledElement." How to change the code?

<Style Selector="Button:pointerover">
    <Setter Property="(ia:Interaction.Behaviors)">
        <ia:BehaviorCollectionTemplate>
            <ia:BehaviorCollection>
                <iac:DataTriggerBehavior Binding="{Binding $parent[Button].(i:VisualStateHelper.Background)}"
                            ComparisonCondition="NotEqual"
                            Value="{x:Null}">
                    <iac:ChangePropertyAction TargetObject="$parent"
                                              PropertyName="(i:VisualStateHelper.Background)"
                                              Value="{Binding $parent[Button].(local:ButtonHelper.HoverBackground)}" />
                </iac:DataTriggerBehavior>
            </ia:BehaviorCollection>
        </ia:BehaviorCollectionTemplate>
    </Setter>
</Style>
wieslawsoltes commented 1 year ago

I think this might be Avalonia related issue as it requires IStyledElement