Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
785
CellValuePresenter.Value is Always Null
posted

Hello All,

In the code below, "data" is *always* coming back null even though "cellValuePresenter" is *always* referring to a valid CellValuePresenter. I'm using the sample data for XamDataGrid (i.e. XamDataGrid.BindToSampleData = "True"), which has no unpopulated cells in it.

My goal is to get at the business data underlying the cell. Why would "data" always be null? Is there another way I can get at the data?

Thanks,
Dave


[ValueConversion(typeof(CellValuePresenter), typeof(Brush))]
public class CellColorFromThreatEventTypeConverter : IValueConverter
{
   public object Convert(
          object value,
          Type targetType,
          object parameter,
          System.Globalization.CultureInfo culture)
   {
      if (value == null || value.ToString() == "Text")
         return Binding.DoNothing; // Never hit

      CellValuePresenter cellValuePresenter = value as CellValuePresenter;

      if (cellValuePresenter == null)
         return Binding.DoNothing; // Never hit

      // This is *always* null!
      object data = cellValuePresenter.Value;

      // ...
   }

   // ...
}

Thanks,
Dave

  • 69686
    Verified Answer
    posted

    Hello Dave,

    I believe this is because in the binding expression you are targetting the CellValuePresenter itself. Instead, please try setting the path to Value and change the converter accordingly. This way you should not get null.