简体   繁体   English

即使目标属性值未更改,也请调用转换器

[英]Call Converter Even if Target Property Value is not Changed

Scenario: I have 2 grid. 场景:我有2个网格。 1 is parent and 2nd is child. 1是父母,2是孩子。 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. 当为不同的父级显示chid时,我想强制调用转换器,但是当子级相同时,它没有调用转换器,因为目标属性没有被更改。

Example: Grid 1 has parent record A and B. Record A has 2 childs. 示例:网格1具有父记录A和B.记录A具有2个子记录。

Record A: 1) Comman Child 记录A:1)Comman Child

Record B: 1) Common Child 2) Record B Child 记录B:1)普通儿童2)记录B儿童

On Selecting Row A and then onmouseover common child calls the converter. 在选择行A然后onmouseover普通子调用转换器。 When Record B is selected it calls converter for just Record B Child and not for Common child. 当选择记录B时,它仅为记录B子项而不是普通子项调用转换器。 As the value is not changed. 由于价值没有改变。

PS: Childs are placed in ChildsObservableCollection and on the selection filtercollection is filled from childObservableCollection. PS: Childs放在ChildsObservableCollection中,选择filtercollection从childObservableCollection中填充。 filtercollection is bounded to child grid. filtercollection与子网格有界。

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 tbTest写了一些例子。

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

Code behind look like this. 代码背后看起来像这样。 UpdateTarget() causes Conveter.Convert call. UpdateTarget()导致Conveter.Convert调用。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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