【发布时间】:2019-10-04 09:33:33
【问题描述】:
我想在使用ToolTip 的DataGridTextColumn 悬停时显示图像。到目前为止它工作得很好,但如果没有可用的图像,我需要禁用工具提示。
到目前为止,这是我的代码:
<DataGridTextColumn Header="{lex:Loc material}" Binding="{Binding Material}" Width="Auto" MinWidth="75" ToolTipService.IsEnabled="{Binding ProductImageExists}" ToolTipService.ShowDuration="99999" ToolTipService.InitialShowDelay="0">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell" BasedOn="{StaticResource MaterialDesignDataGridCell}">
<Setter Property="ToolTip">
<Setter.Value>
<Image Source="{Binding ProductImage}" Width="250" />
</Setter.Value>
</Setter>
</Style>
</DataGridTextColumn.CellStyle>
输出结果
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=ProductImageExists; DataItem=null; target element is 'DataGridTextColumn' (HashCode=42700980); target property is 'IsEnabled' (type 'Boolean')
为什么工具提示有另一个数据上下文?如何将其设置为正确的?
【问题讨论】:
标签: c# wpf mvvm datacontext