避免空矩形工具提示datagrid单元格?任何建议 [英] Avoid empty rectangular tooltip datagrid cell? Any suggestion
问题描述
嗨
我尝试将Property value绑定到DataGridTextColumn。如果我将鼠标悬停在带有空单元格的DatagridCell上。显示一个空框。这是我现在使用的实际代码
Hi
I have tried binding Property value to DataGridTextColumn. If i hover on DatagridCell with empty cell.One empty box showing up. This is actual code am using now
<DataGridTextColumn Header="Contact Name" IsReadOnly="True" Binding="{Binding Path=ContactName}">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="ToolTip" Value="{Binding Path=ContactName}" />
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
我尝试了什么:
我试过下面的代码,它没有显示工具提示一点都不任何帮助将不胜感激。为此添加了命名空间。
What I have tried:
I tried the below code , it does not show tooltip at all. Any help would be appreciated.For this added a namespace as well.
<pre> <DataGridTextColumn Header="ContactName" IsReadOnly="True" Binding="{Binding Path=ContactName}" ToolTipService.ToolTip="{Binding Path=ContactName}" ToolTipService.IsEnabled="True"> <DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="ToolTip" Value="{x:Static system:String.Empty}">
<Setter Property="ToolTipService.IsEnabled" Value="False" />
</Trigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
推荐答案
我不确定你的意思是空单元格因此,我无法为您的问题陈述提供准确的解决方案,但您至少有3个选择可供探索:
1>使用FallBack绑定选项:
您可以指定在普通数据项不可用时显示某个数据项:
WPF绑定FallbackValue设置为绑定 - 堆栈溢出 [ ^ ]
- 使用链接页面的问题部分中显示的 FallbackValue ,或者通过答案部分中显示的
I am not exactly sure what you mean by an empty cell so I cannot give an exact solution to your less than precise problem statement but you have at least 3 options to explore:
1> Use a FallBack binding option:
You can specify to show a certain data item when the normal data item is not available:
WPF Binding FallbackValue set to Binding - Stack Overflow[^]
- Either use the FallbackValue as shown in the question section of the linked page or use the alternative binding via
PriorityBinding
使用替代绑定。 br $> b $ b
2>使用转换器:您始终可以使用标准 IValueConverter
来执行与1>中相同的默认值显示逻辑。不同之处在于转换器是一个C#/ VB.Net代码片段,如果您看到许多不同的情况并希望以不同的方式对它们作出反应,您可以选择集成不同的和更大的场景。
3>
shown in the answer section.
2> Use a converter: You can always use a statndard IValueConverter
to do essantially the same default value display logic as in 1>. The Difference is that the converter is a C#/VB.Net piece of code that gives you way may options to integrate different and larger scenarios should you see many different cases and want to react to them in a different fashion.
3> An
IMultiValueConverter
为您提供了最大的灵活性和选项,可以从多个源绑定并将值转换为通用格式。这是一个我刚输入的例子(没有编译) - 它需要一个字符串和一个布尔值(例如IsEnabled)作为输入并将其转换为字符串。
gives you most flexibility and options towards binding from multiple sources and converting values into a common format. Here is an example that I just typed out (have not compiled it) - it takes a string and a boolean value (eg IsEnabled) as input and converts it into a string.
[ValueConversion(typeof(string), typeof(string))]
public class ItemTypeDisplayNameToTextConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values == null)
return Binding.DoNothing;
if (values.Length != 2)
return Binding.DoNothing;
var item = values[0] as string;
if (item == null)
return Binding.DoNothing;
if (values[1] is bool == false)
return Binding.DoNothing;
bool isEnabled = (bool)values[1];
if (isEnabled == false) // The cell was not enabled
return string.Empty;
if (string.IsNUllOrEmtpy(item)) // There was no string being successfully bound
return string.Empty;
return item;
}
object[] IMultiValueConverter.ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
您可以下载示例解决方案,在转换器中设置断点,然后启动演示如果你想看到这个原位工作:
主要的InplaceEditBoxLib / ItemTypeDisplayNameToTextConverter.cs·Dirkster99 / InplaceEditBoxLib·GitHub [ ^ ]
我希望这会有所帮助。如果您能解决问题或者看到其他问题,请告诉我。
You can download a sample solution, set a breakpoint in the converter, and start the demo if you want to see this working in-situ:
InplaceEditBoxLib/ItemTypeDisplayNameToTextConverter.cs at master · Dirkster99/InplaceEditBoxLib · GitHub[^]
I hope this helps. Let me know if you were able to solve your problem or if you see a different problem.
这篇关于避免空矩形工具提示datagrid单元格?任何建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!