WPF:绑定条件与物业,XamlParseException无论是使用 [英] WPF: Condition Binding versus Property, XamlParseException using either

查看:189
本文介绍了WPF:绑定条件与物业,XamlParseException无论是使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个条件麻烦了 MultiTrigger 。如果我做了以下内容:

 <条件绑定={绑定的RelativeSource = {的RelativeSource
    AncestorType = {X:类型的ListView}}}属性=IsEnabledVALUE =真/>

然后我得到这个异​​常:


  

条件不能同时使用属性和绑定。在标记文件对象System.Windows.Condition错误


然而,当我做到以下几点:

 <条件绑定={绑定的RelativeSource = {的RelativeSource
    AncestorType = {X:类型的ListView}},路径= IsEnabled}VALUE =真/>

然后我得到这个异​​常:


  

必须指定属性和值的触发。在标记文件对象System.Windows.Condition错误


怎么办?如果它的事项,这里的整个触发:

 < MultiTrigger>
    < MultiTrigger.Conditions>
        <条件绑定={绑定路径= IsSelected}VALUE =真/>
        <条件绑定={绑定路径= ItemsControl.AlternationIndex}
                   值=0/>
        <条件绑定={绑定的RelativeSource = {的RelativeSource
            AncestorType = {X:类型的ListView}},路径= IsEnabled}
                   值=真/>
    < /MultiTrigger.Conditions>
    < setter属性=背景
            VALUE ={StaticResource的evenSelected}/>
    < setter属性=BorderBrush
            VALUE ={StaticResource的evenSelectedBorder}/>
< / MultiTrigger>


解决方案

在这种情况下,API是混乱的。 条件用于两种不同类型的多触发器,和所使用的特性是不同的。当使用 MultiTrigger ,你会使用属性属性。当使用 MultiDataTrigger (这是你所需要的),您可以指定一个绑定。所以,如果你只是切换您的code使用 MultiDataTrigger ,你会好走:

 < MultiDataTrigger>
    < MultiDataTrigger.Conditions>
        <条件绑定={绑定路径= IsSelected}VALUE =真/>
        <条件绑定={绑定路径= ItemsControl.AlternationIndex}
                   值=0/>
        <条件绑定={绑定的RelativeSource = {的RelativeSource
            AncestorType = {X:类型的ListView}},路径= IsEnabled}
                   值=真/>
    < /MultiDataTrigger.Conditions>
    < setter属性=背景
            VALUE ={StaticResource的evenSelected}/>
    < setter属性=BorderBrush
            VALUE ={StaticResource的evenSelectedBorder}/>
< / MultiDataTrigger>

I'm having trouble with a Condition for a MultiTrigger. If I do the following:

<Condition Binding="{Binding RelativeSource={RelativeSource
    AncestorType={x:Type ListView}}}" Property="IsEnabled" Value="True"/>

Then I get this exception:

Condition cannot use both Property and Binding. Error at object 'System.Windows.Condition' in markup file

However, when I do the following:

<Condition Binding="{Binding RelativeSource={RelativeSource
    AncestorType={x:Type ListView}}, Path=IsEnabled}" Value="True"/>

Then I get this exception:

Must specify both Property and Value for Trigger. Error at object 'System.Windows.Condition' in markup file

What gives? If it matters, here's the entire trigger:

<MultiTrigger>
    <MultiTrigger.Conditions>
        <Condition Binding="{Binding Path=IsSelected}" Value="True"/>
        <Condition Binding="{Binding Path=ItemsControl.AlternationIndex}"
                   Value="0"/>
        <Condition Binding="{Binding RelativeSource={RelativeSource
            AncestorType={x:Type ListView}}, Path=IsEnabled}"
                   Value="True"/>
    </MultiTrigger.Conditions>
    <Setter Property="Background"
            Value="{StaticResource evenSelected}" />
    <Setter Property="BorderBrush"
            Value="{StaticResource evenSelectedBorder}" />
</MultiTrigger>

解决方案

The API in this case is confusing. Condition is used for two different types of multi-triggers, and the properties used are different. When using MultiTrigger, you will use the Property and Value properties. When using MultiDataTrigger (which is what you need), you specify a Binding and a Value. So, if you just switch your code to use a MultiDataTrigger, you'll be good to go:

<MultiDataTrigger>
    <MultiDataTrigger.Conditions>
        <Condition Binding="{Binding Path=IsSelected}" Value="True"/>
        <Condition Binding="{Binding Path=ItemsControl.AlternationIndex}"
                   Value="0"/>
        <Condition Binding="{Binding RelativeSource={RelativeSource
            AncestorType={x:Type ListView}}, Path=IsEnabled}"
                   Value="True"/>
    </MultiDataTrigger.Conditions>
    <Setter Property="Background"
            Value="{StaticResource evenSelected}" />
    <Setter Property="BorderBrush"
            Value="{StaticResource evenSelectedBorder}" />
</MultiDataTrigger>

这篇关于WPF:绑定条件与物业,XamlParseException无论是使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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