microsoft / XamlBehaviors

This is the official home for UWP XAML Behaviors on GitHub.
MIT License
697 stars 112 forks source link

Having difficulty using ChangePropertyAction on an attached property #150

Closed kareemsulthan07 closed 5 years ago

kareemsulthan07 commented 5 years ago

I'm using DataTriggerBehavior on a button to change its tooltip value when a view model property change. When using ChangePropertyAction to change value of ToolTipService.ToolTip attached property on the button, it is throwing this exception System.ArgumentException - Cannot find a property named Windows.UI.Xaml.PropertyPath on type Button.

This is the sample xaml line I'm using. Am I specifying the attached property correctly? What is wrong I'm doing in specifying attached property in ChangePropertyAction.

pedrolamas commented 5 years ago

For the record, this is expected given the current implementation, so I wouldn't consider this exactly a bug!

The problem here is that the Tooltip property you are trying to update is not defined on the Button class, but under the ToolTipService.

To mitigate this, I recommend building your own custom implementation of IAction for your project. You can use the current ChangePropertyAction code as a base to start, and then change the UpdatePropertyValue method to your needs (you probably won't even need the PropertyName property as you'd already know which property to update: the TooltipService.ToolTip).

michael-hawker commented 4 years ago

Just hit this as well, bit frustrating we can't use the same (namespace:Parent.Property) attached property syntax that we use for Bindings. Would be nice to have another helper/action for this type of scenario...

Could be handy to leave this issue open to make it easier to find for the future? Or update the wiki page to call this limitation out in the docs?