WPF。对于多触发条件,“属性”必须具有非空值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21084676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 10:30:03  来源:igfitidea点击:

WPF. Must have non-null value for 'Property' for multitrigger condition

c#wpfxaml

提问by nelly2k

Have multitrigger, one of the conditions is not null, so if StowedAssetDetailedThumbnailViewModel != null then set template

有多重触发,条件之一不为空,所以如果 StowedAssetDetailedThumbnailViewModel != null 那么设置模板

<Style.Triggers>
    <MultiTrigger>
        <MultiTrigger.Conditions>
            <Condition Property="IsSelected" Value="true" />
            <Condition Binding="{Binding Path=StowedAssetDetailedThumbnailViewModel,
                                         Converter={StaticResource isNull}}"
                       Value="False"/>
        </MultiTrigger.Conditions>
        <Setter Property="Template" Value="{StaticResource SelectedTemplate}" />
    </MultiTrigger>
</Style.Triggers>

Using simple converter:

使用简单的转换器:

return isNull == null;

the error is Must have non-null value for Property

错误是 属性必须具有非空值

UPDATE: Thanks, the final solution is

更新:谢谢,最终的解决方案是

<Style.Triggers>
    <MultiDataTrigger>
        <MultiDataTrigger.Conditions>
            <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}"
                       Value="true" />
            <Condition Binding="{Binding Path=StowedAssetDetailedThumbnailViewModel,
                                 Converter={StaticResource isNull}}"
                                 Value="false"/>
        </MultiDataTrigger.Conditions>

        <Setter Property="Template" Value="{StaticResource SelectedTemplate}" />
    </MultiDataTrigger>
</Style.Triggers>

回答by Patrick Y

You'll want to use a MultiDataTrigger in this case. A MultiTrigger can only be triggered by dependency properties.

在这种情况下,您将需要使用 MultiDataTrigger。MultiTrigger 只能由依赖属性触发。