与转换器绑定失败

时间:2011-11-21 13:10:56

标签: c# .net wpf xaml data-binding

我正在尝试设置一些绑定。还有,我正在使用MVVM模式。

我的xaml代码中有这个控件

<Grid.Resources>
    <src:ActivityViewToToolTipContentConverter x:Key="tooltipConverter"></src:ActivityViewToToolTipContentConverter>
    <SolidColorBrush x:Key="CustomNonWorkingBrush" Color="#DFE9F2" Opacity="0.75"/>
</Grid.Resources>

<gantt:GanttControl Name="GanttChart"
                    IDBinding="{Binding TaskID}"
                    NameBinding="{Binding TaskName}"
                    IndentLevelBinding="{Binding IndentLevel}"
                    StartTimeBinding="{Binding StartDate}"
                    PredecessorIndicesBinding="{Binding PredecessorIndices}"
                    DescriptionBinding="{Binding TaskResponsible}"
                    SortOrderBinding="{Binding SortOrder}"
                    ToolTipContentBinding="{Binding ActualTaskResponsibleDepartment, Converter={StaticResource tooltipConverter}}" //It is this line I am talking about
                    TemplateApplied="GanttChart_TemplateApplied"
                    CanUserReorderRows="True"
                    NonWorkingTimeBackground="{StaticResource CustomNonWorkingBrush}"
                    SyncRowBackgrounds="True"
                    AdjustDurationOnAssignment="False"
                    DependencyLineAdded="GanttChart_DependencyLineChanged"
                    DependencyLineRemoved="GanttChart_DependencyLineChanged"

                    Loaded="GanttChart_Loaded"
                    />

我的转换器位于另一个名为“ActivityViewToToolTipContentConverter.cs”的文件中

当我运行代码时,我得到了这个例外:

  

System.Windows.Data错误:40:BindingExpression路径错误:   'object'上找不到'ActualTask​​ResponsibleDepartment'属性   ''GanttActivityView'(Name ='')'。   BindingExpression:路径= ActualTask​​ResponsibleDepartment;   DataItem ='GanttActivityView'(Name ='');目标元素是'ToolTip'   (名称= 'TaskTooltip'); target属性是'Content'(类型'Object')

2 个答案:

答案 0 :(得分:3)

当绑定失败时,从未与转换器有任何关系,并且错误明确表示您尝试绑定到在DataContext视图上找不到的属性。

答案 1 :(得分:2)

您的DataContext(绑定到GanttActivityView)是否属性为ActualTask​​ResponsibleDepartment?