Click here to Skip to main content
15,905,781 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

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}">
<Style TargetType="DataGridCell">
<Setter Property="ToolTip" Value="{Binding Path=ContactName}" />

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">
<Trigger Property="ToolTip" Value="{x:Static system:String.Empty}">
<Setter Property="ToolTipService.IsEnabled" Value="False" />
Updated 15-Jun-18 3:41am

1 solution

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
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
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();

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.
Share this answer
kida atlantis 18-Jun-18 5:24am    
Thanks alot, It helped me to solve my problem.
Dirk Bahle 18-Jun-18 6:07am    
No problem, glad to hear it helped - You should set the stars for the answer to indicate the answer for others who may be searching a resolution for the same problem ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900