【问题标题】:Property can not be null on Trigger触发器上的属性不能为空
【发布时间】:2012-02-14 09:20:38
【问题描述】:
<Style TargetType="controls:EventTimeView">      
    <Style.Triggers>         
        <Trigger Property="PositioningMethod" Value="Column" >
            <Setter Property="Background" Value="Black" />
        </Trigger>
    </Style.Triggers>
</Style>

PositioningMethod是一个枚举类型的EventTimeView的依赖属性。

结果:

System.InvalidOperationException occurred
Message=Property can not be null on Trigger.
Source=PresentationFramework
StackTrace:
   at System.Windows.StyleHelper.UpdateTables(PropertyValue& propertyValue, FrugalStructList`1& childRecordFromChildIndex, FrugalStructList`1& triggerSourceRecordFromChildIndex, FrugalStructList`1& resourceDependents, HybridDictionary& dataTriggerRecordFromBinding, HybridDictionary childIndexFromChildName, Boolean& hasInstanceValues)
InnerException: 

我不知道可能出了什么问题。例外太模糊:哪个属性?什么是空?

【问题讨论】:

    标签: wpf xaml dependency-properties


    【解决方案1】:

    仔细检查 PositioningMethodProperty 的 DependencyProperty 定义 - 确保拥有类型实际上是定义 DP 的类。

    【讨论】:

      【解决方案2】:

      尽管这个问题是多年前提出的并且已经得到解答,但我还是分享这个旁注,以防它对任何人有所帮助:

      我收到此错误是因为我使用的是Trigger 而不是DataTrigger,并且我将触发器绑定到数据上下文中的属性,而不是控件本身中的属性。一旦我将Trigger 标签更改为DataTrigger,错误就消失了。

      【讨论】:

        【解决方案3】:

        尝试以如下样式预先设置背景属性:

            <Style TargetType="controls:EventTimeView">   
            <Setter Property="Background" Value="Transparent" />
        
            <Style.Triggers>         
                <Trigger Property="PositioningMethod" Value="Column" >
                    <Setter Property="Background" Value="Black" />
                </Trigger>
            </Style.Triggers>
        </Style>
        

        【讨论】:

          猜你喜欢
          • 2013-01-20
          • 1970-01-01
          • 2020-11-24
          • 1970-01-01
          • 2010-11-17
          • 2013-02-16
          • 1970-01-01
          • 2020-10-29
          • 2017-04-10
          相关资源
          最近更新 更多