views:

31

answers:

0

After a substantial refactoring complete with 100% passing tests, it turns out that firing up the UI shows it is now impossible to select an item in the list. What is happening is that the selected item is called twice - the first time with the correct item that was selected. But then it is called again with a value of null.

Looking through the stack only shows a bunch of wpf databinding related routines, and no obvious place in my codebase that might be causing the second call to set the selected item. I don't see any binding errors either, although it does seem like the binding is wrong somewhere.

I'm hoping that someone can spot the error or at least ask a question that will lead to finding it.

Cheers,
Berryl

Here are some XAML binding snippets that seem relevant:

<ListView ItemsSource="{Binding Subjects.View}" 
          IsSynchronizedWithCurrentItem="True"
          SelectedItem="{Binding SelectedSubject}"
       .....

<Button Command="{Binding Path=PickCommand}" CommandParameter="true"
                Content="_Select" IsDefault="True" .../>

And some snippets of code in an abstract base class:

public CollectionViewSource Subjects { get; private set; }

public T SelectedSubject 
{ 
    get { return _selectedSubject; }
    set {
        var oldSubject = _selectedSubject;
        var wasChanged = ApplyPropertyChange<SubjectPickerBase<T>, T>(ref _selectedSubject, x => x.SelectedSubject, value);
        if (!wasChanged) return;

        if (oldSubject != null)
        {
            Check.Invariant(oldSubject.Availability == AvailabilityStatus.Unavailable);
            oldSubject.FlipAvailabilityStatus();
            Check.Invariant(oldSubject.Availability == AvailabilityStatus.Available);
        }
        if (_selectedSubject != null)
        {
            Check.Invariant(_selectedSubject.Availability == AvailabilityStatus.Available);
            selectedSubject.FlipAvailabilityStatus();
            Check.Invariant(_selectedSubject.Availability == AvailabilityStatus.Unavailable);
        }

public VmCommand<object> PickCommand
{
    get { return _pickCommand ?? (_pickCommand = new VmCommand<object>(_pick, _canPick)); }
    }
private VmCommand<object> _pickCommand;

private bool _canPick(object o) {
    return !ReferenceEquals(SelectedSubject, null);
}

private void _pick(object dialogResult)    {...}