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
900
Fields bound to properties that return null re-evaluate too much.
posted

Hi,

Our team noticed that when a field in a XamDataGrid record is bound to a property that returns null, that property's setter gets re-evaluated multiple times when the record is loaded and also re-evaluates when the mouse hovers over the record.

This is having some very negative and adverse behavior for us since the grid control seems to be making an assumption about what null means, but from the data standpoint its a legitimate value.  Yet, the grid doesn't treat it like any other value.

The only workaround I've found is to specify AlternateBinding with AlternateBindingRetentionMode="Retain". However, we have dozens of grids with hundreds of fields already declared, and it will be a massive PITA to go and migrate the field declarations for each.

1. Why does the grid re-evaluate fields that are null? Is this by design?
2. Can this behavior be set on a global level so that alternate binding isn't specified?

Thanks,
Bedo

Here is a sample app that demonstrates the behavior: Simply brake where DoubleNullable and ObjectNull's getters return. Then run and move the mouse over the grid.

---- XAML -----

<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dataPresenter="http://infragistics.com/DataPresenter"
Title="MainWindow" Height="350" Width="525">
<dataPresenter:XamDataGrid 
DataSource="{Binding Items}"/>
</Window>

---- CODE ----

using System.Collections.ObjectModel;
using System.Windows;


namespace WpfApplication1 {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
DataContext = new TestViewModel();}
}

public class TestViewModel {
public ObservableCollection<Item> Items { get; private set; }
public TestViewModel() {
Items = new ObservableCollection<Item> { new Item() };}
}

public class Item {
public double Double1 { get { return 1; } }
public double DoubleNaN { get { return double.NaN; } }
public double? DoubleNullable {
//This gets called multiple times when the mouse hovers over the record
get { return null; }
}

public object Object { get { return new object(); } }
public object ObjectNull {
//This gets called multiple times when the mouse hovers over the record
get { return null; }
}

}}