Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Binding without path with converter, update

I have a binding without path using a converter. This is because the converter will use many properties of the object to build the text for the tooltip. But when one property changes (INotifyPropertyChanged is implemented and OnPropertyChanged raised), this binding without path does not get updated. I guess because it does not bind to a specific property.

How to tell that it has to update?


I try to be more specific:

The bar object has a 'Start' property. When I change this the bar moves in time because the binding gets directly to the Start property. So the notification works for single properties. But the tooltip binding is {Binding Converter={StaticResource TooltipConverter}} and does not bind to a specific property. When 'Start' changes, the bar is moved but the tooltip does not update because the tooltipconverter is not called again.

The bar is one object in an ObservableCollection<Bar>. Should the bar tell the collection or the view model? Normally is would not have any relationship to it.

like image 398
ZoolWay Avatar asked Mar 21 '23 16:03

ZoolWay


1 Answers

One possible workaround is:

Give your object a ItSelf property (or other name) like:

public Object ItSelf
{
    get { return this; }
}

Instead of binding

{Binding Converter={StaticResource TooltipConverter}}

use

{Binding ItSelf, Converter={StaticResource TooltipConverter}}

Then you raise OnPropertyChanged for ''ItSelf'' for every property. So you can signal an update for the whole object whenever it was used in a binding.

public DateTime Start
{
    get { return this.start; }
    set { this.start = value; OnPropertyChanged("Start"); OnPropertyChanged("ItSelf");
}

I got this to work a bit faster but would like to test out AttachedBehavior for this like stated by @AnatoliiG so I will accept an answer later.

like image 170
ZoolWay Avatar answered Apr 09 '23 14:04

ZoolWay