与转换器绑定失败

本文关键字:失败 绑定 转换器 | 更新日期: 2023-09-27 18:15:14

我正在尝试设置一些绑定。供参考,我正在使用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。数据错误:40:BindingExpression路径错误' actualtaskresponledepartment '属性在'object'上找不到"GanttActivityView (Name = ")。BindingExpression:路径= ActualTaskResponsibleDepartment;DataItem ="GanttActivityView"(Name = ");目标元素是"工具提示"(Name = ' TaskTooltip ');目标属性为"Content"(类型为"Object")

与转换器绑定失败

当绑定失败时,这与转换器没有任何关系,并且正如错误明显所述,您试图绑定到在DataContext视图中找不到的属性。

你的DataContext(绑定到GanttActivityView)一个属性actualtaskresponledepartment ?