(多个)MultiDataTrigger与转换器的效率 [英] Efficiency of (multiple) MultiDataTrigger vs. Converter

查看:194
本文介绍了(多个)MultiDataTrigger与转换器的效率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在分析一些XAML,这些XAML使用的样式广泛使用了多值转换器),尤其是由于无法调试MultiDataTriggers.

I'm currently analyzing some XAML that uses style that make extensive use of MultiDataTriggers (8-10 multi data triggers per style, with 4-6 conditions per trigger). When looking at this I'm considering whether it would be more efficient to use a converter (or multi value converter), especially as MultiDataTriggers cannot be debugged.

有人可以权威地说明如何编译MultiDataTriggers吗?我了解到条件是ANDed ,会以捷径为特色吗?

Can anyone authoritatively state how MultiDataTriggers are compiled? I understand that the Conditions are ANDed together, is this compiled in such a way that short cutting is featured?

多个MultiDataTriggers呢?它们是否短路,以使第一个完全满足要求而导致评估停止?还是如果有几个人满意,他们都将以最后一个获胜者来评估吗?

What about multiple MultiDataTriggers? Are they short circuited so that the first one fully satisfied causes evaluation to stop? Or are they all evaluated with the last one winning if several are satisfied?

推荐答案

Triggers are evaluated from top to bottom.它适用于各种触发器(Trigger,DataTrigger,MultiTrigger和MutliDataTrigger).

Triggers are evaluated from top to bottom. It holds true for all sorts of triggers (Trigger, DataTrigger, MultiTrigger and MutliDataTrigger).

多个MultiDataTriggers呢?他们短路了吗 第一个完全满意的结果导致评估停止?或者是 如果都满意,他们都会以最后一个获胜者来评估?

What about multiple MultiDataTriggers? Are they short circuited so that the first one fully satisfied causes evaluation to stop? Or are they all evaluated with the last one winning if several are satisfied?

如上所述,触发器从上到下进行评估.因此,如果第一个条件满足所有条件并不意味着不会评估其他触发器.将评估所有应用于更改后的属性的触发器,如果​​其中两个触发器在触发器中设置了相同的属性,则分别单击last trigger always wonoverrides the property set by first trigger.

As stated triggers are evaluated from top to bottom. So, in case first one satisfy all conditions doesn't mean further triggers won't be evaluated. All triggers applied on changed property are evaluated and in case any two of them are setting same property inside a trigger then last trigger always won and overrides the property set by first trigger.

<TextBlock>
   <TextBlock.Style>
      <Style TargetType="TextBlock">
          <Style.Triggers>
             <DataTrigger Binding="{Binding IsEnable}" Value="True">
                <Setter Property="Text" Value="Test1"/>
             </DataTrigger>
             <DataTrigger Binding="{Binding IsEnable}" Value="True">
                <Setter Property="Text" Value="Test2"/>
             </DataTrigger>
           </Style.Triggers>
      </Style>
  </TextBlock.Style>
</TextBlock>

IsEnable评估为真时,文本将始终为Test2.

Text will always be Test2 when IsEnable evaluates out to be true.

有人可以权威地说明如何编译MultiDataTriggers吗?一世 了解条件是与在一起的,这是在 这样的快捷方式是特色吗?

Can anyone authoritatively state how MultiDataTriggers are compiled? I understand that the Conditions are ANDed together, is this compiled in such a way that short cutting is featured?

是的,MultiDataTrigger中具有快捷方式,即first condition evaluate to be false, second condition won't be checked.此示例验证了这一点-

Yeah, short cutting is featured in MultiDataTrigger i.e. if first condition evaluate to be false, second condition won't be checked. This sample validates this -

<TextBlock>
   <TextBlock.Style>
       <Style TargetType="TextBlock">
           <Style.Triggers>
               <MultiDataTrigger>
                   <MultiDataTrigger.Conditions>
                       <Condition Binding="{Binding IsEnable,
                             Converter={StaticResource SingleValueConverter}}" 
                                  Value="True"/>
                       <Condition Binding="{Binding IsEnable,
                             Converter={StaticResource SingleValueConverter}}"
                                  Value="True"/>
                    </MultiDataTrigger.Conditions>
                    <Setter Property="Text" Value="Test"/>
                </MultiDataTrigger>
          </Style.Triggers>
       </Style>
   </TextBlock.Style>
</TextBlock>

在两个条件下都应用了转换器,但是如果IsEnabledfalseconverter gets hit only once,则因为第一个条件得出的结果为假.但是,如果IsEnabledtrue,则由于成功满足第一个条件,所以converter gets hit twice.

On both conditions a converter is applied but in case IsEnabled is false, converter gets hit only once because first condition evaluates out to be false. But in case IsEnabled is true, converter gets hit twice since first condition is meet successfully.

这篇关于(多个)MultiDataTrigger与转换器的效率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆