1
votes

Quite a few posts around this area, but none are helping me... here's the scenario: I've got two "season" drop downs to simulate a range. If you pick a season in the begin range one, the viewmodele automatically sets the property bound to the end range to the same season (so it defaults to a single year and not a range. Here's what the XAML looks like (removed lot of the formatting attibutes for readability):

<ComboBox ItemsSource="{Binding AvailableSeasons, Mode=OneWay}" 
          SelectedItem="{Binding SelectedBeginRangeSeason, Mode=TwoWay}" 
          ItemTemplate="{DynamicResource SeasonItemShortFormat}" />
<ComboBox ItemsSource="{Binding AvailableSeasons, Mode=OneWay}" 
          SelectedItem="{Binding SelectedEndRangeSeason, Mode=TwoWay}" 
          ItemTemplate="{DynamicResource SeasonItemShortFormat}" />

The properties in the view model look like this:

private Season _selectedBeginRangeSeason;
private const string SelectedBeginRangeSeasonPropertyName = "SelectedBeginRangeSeason";
public Season SelectedBeginRangeSeason {
  get { return _selectedBeginRangeSeason; }
  set {
    if (_selectedBeginRangeSeason != value) {
      var oldValue = _selectedBeginRangeSeason;
      _selectedBeginRangeSeason = value;

      RaisePropertyChanged<Season>(SelectedBeginRangeSeasonPropertyName, oldValue, value, true);
    }
  }
}

private Season _selectedEndRangeSeason;
private const string SelectedEndRangeSeasonPropertyName = "SelectedEndRangeSeason";
public Season SelectedEndRangeSeason {
  get { return _selectedEndRangeSeason; }
  set {
    if (_selectedEndRangeSeason != value) {
      Debug.WriteLine("Updating property SelectedEndRangeSeason...");

      var oldValue = _selectedEndRangeSeason;
      _selectedEndRangeSeason = value;

      Debug.WriteLine("Broadcasting PropertyChanged event for property SelectedEndRangeSeason...");
      RaisePropertyChanged<Season>(SelectedEndRangeSeasonPropertyName, oldValue, value, true);
    }
  }
}

private void UpdateSelectedSeasonSelectors() {
  // if the end range isn't selected...
  if (_selectedEndRangeSeason == null) {
    // automatically select the begin for the end range
    SelectedEndRangeSeason = _selectedBeginRangeSeason;
  }
}

I've verified the end property is being changed both with the debug statements and with unit tests, but the UI isn't changing when I select it... can't figure out what's going on and have looked at this so many different ways...

2
This question sounds similar to yours. Did you try the answer on that one?RMart

2 Answers

2
votes

Did you get the SelectedSeason from the AvailableSeasons collection? If not, did you implement anything special to compare Seasons?

For example, suppose you have

<ComboBox ItemsSource="{Binding AvailableSeasons}" 
          SelectedItem="{Binding SelectedSeason}" />

If SelectedSeason = new Season(); the SelectedItem binding won't work because new Season(); does not exist in AvailableSeasons.

You'll need to set SelectedSeason = AvailableSeasons[x] for SelectedItem to work because that makes the two items exactly the same. Or you can implement some custom method to compare the two seasons to see if they're the same. Usually I just overwrite the ToString() method of the class being compared.

1
votes

Try to fire an event from the ViewModel to notify the UI to refresh the calendar.