本文介绍了MultiDataTrigger 与具有多重绑定的 DataTrigger的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到过这样一种情况,我可以通过使用 MultiDataTrigger 或者使用带有 MultiBindingDataTrigger 轻松实现相同的功能.是否有任何实质性理由更喜欢一种方法而不是另一种方法?

I encountered a situation where I can easily achieve the same functionality by using a MultiDataTrigger or, alternately, using a DataTrigger with a MultiBinding. Are there any substantive reasons to prefer one approach over the other?

使用多数据触发器:

<MultiDataTrigger>
    <MultiDataTrigger.Conditions>
        <Condition Binding="{Binding Path=SomePath}" Value="SomeValue"/>
        <Condition Binding="{Binding Path=SomeOtherPath, Converter={StaticResource SomeConverter}}" Value="SomeOtherValue"/>
    </MultiDataTrigger.Conditions>
    <MultiDataTrigger.EnterActions>
        <BeginStoryboard Storyboard="{StaticResource MyStoryboard}"/>
    </MultiDataTrigger.EnterActions>
</MultiDataTrigger>

使用多重绑定:

<DataTrigger Value="foo">
    <DataTrigger.Binding>
        <MultiBinding Converter="{StaticResource fooConv}"/>
            <Binding Path=SomePath/>
            <Binding Path=SomeOtherPath/>
        </MultiBinding>
    </DataTrigger.Binding>
    <DataTrigger.EnterActions>
        <BeginStoryboard Storyboard="{StaticResource MyStoryboard}"/>
    </DataTrigger.EnterActions>
</DataTrigger>

推荐答案

Multibinding 需要一个转换器,除了极少数情况(使用 StringFormat).

Multibinding requires a converter for all but the rarest circumstances (using StringFormat).

MultiTrigger 只需要一个转换器即可将您的绑定结果转换为 booleans.

MultiTrigger only requires a converter to get your binding results into booleans.

这篇关于MultiDataTrigger 与具有多重绑定的 DataTrigger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 20:52