简体   繁体   中英

Call Converter Even if Target Property Value is not Changed

Scenario: I have 2 grid. 1 is parent and 2nd is child. On each row Mouseover i am calling a converter. When record in parent is selected it's subsequent child records are shown in child grid. On mouseover of child row it calls converter.

Issue: The issue i'm facing is that multiple parents records could have same child. I want to call converter forcefully when chid is shown for different parent, but when child is same it didn't calls the converter as the target property was not changed.

Example: Grid 1 has parent record A and B. Record A has 2 childs.

Record A: 1) Comman Child

Record B: 1) Common Child 2) Record B Child

On Selecting Row A and then onmouseover common child calls the converter. When Record B is selected it calls converter for just Record B Child and not for Common child. As the value is not changed.

PS: Childs are placed in ChildsObservableCollection and on the selection filtercollection is filled from childObservableCollection. filtercollection is bounded to child grid.

I know it's default behavior of converter that it is only called when target property value is changed, but here i want to forcefully call the converter on row-binding/changing. Any Idea? Thanks in Advance.

You can try forcefully update binding target. I've wrote some example with TextBlock tbTest .

<TextBlock Name="tbTest" Text="{Binding TestInt, Converter={StaticResource intToStr}}" />

Code behind look like this. UpdateTarget() causes Conveter.Convert call.

var bindingExpression = tbTest.GetBindingExpression( TextBlock.TextProperty );
bindingExpression.UpdateTarget();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM