我在下面有以下转换器,它会引发运行时错误:
System.Windows.Data警告:40:BindingExpression路径错误:'文字' 在' object'上找不到的属性'' ContentPresenter' (名称='')&#39 ;. BindingExpression:路径= Content.Text;的DataItem =' DataGridCell' (名称='&#39);目标元素是' DataGridCell' (名称='&#39);目标财产 是IsTextMatch' (键入'布尔')
<DataGrid.Resources>
<helpers:SearchValueConverter x:Key="SearchValueConverter" />
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="helpers:SearchBehaviours.IsTextMatch">
<Setter.Value>
<MultiBinding Converter="{StaticResource SearchValueConverter}">
<Binding RelativeSource="{RelativeSource Self}" Path="Content.Text" />
<Binding RelativeSource="{RelativeSource Self}" Path="(helpers:SearchBehaviours.SearchValue)" />
</MultiBinding>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="helpers:SearchBehaviours.IsTextMatch" Value="True">
<Setter Property="Background" Value="Orange" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
有人能看出问题所在吗?
答案 0 :(得分:0)
DataGridCell.Content
中的对象可能没有Text
属性。
尝试绑定到Content
:
<Binding RelativeSource="{RelativeSource Self}" Path="Content" />
然后测试&#34;内容的类型&#34;:
public object Convert(object[] values, ...
{
var textBlock = values[0] as TextBlock;
if (textBlock != null)
{
// do something with textBlock.Text ...