I have a class TransmissionPresenter that has IsEnabled property that I bind to DataGridRow IsEnabled.
I'm binding the DataGrid ItemsSource to ICollectionView.
There's a button in the row that if clicked I change the IsEnabled to false. This works. However, when I refresh the ICollectionView, the IsEnabled is back to true.
Here's some code:
//ViewModel public TransmissionListFilter Filter { get; private set; } public ICollectionView Transmissions { get { return Filter.Transmissions; } set { Filter.Transmissions = value; RaisePropertyChanged(() => this.Transmissions); }
//TransmissionListFilter private ICollectionView transmissions; public ICollectionView Transmissions { get { return transmissions; } set { transmissions = value; value.Filter = (x) => ApplyFilter(x); transmissions.Refresh(); RaisePropertyChanged(() => this.Transmissions); } } private bool ApplyFilter(object x) { if (x == null) return true; var transmission = x as Transmission; if (Id.HasValue) if (!transmission.Id.Value.Equals(Id)) return false; if (!string.IsNullOrEmpty(Name)) if (!transmission.Name.ToLower().Contains(Name.ToLower())) return false; if (Date.HasValue) if (!transmission.Date.Equals(Date.Value)) return false; if (Status != TransmissionStatus.None) { if (!transmission.Status.Equals(Status)) return false; } if (Category != null && Category != Category.All) if (transmission.CategoryId != Category.Id) return false; return true; } private string name; public string Name { get { return name; } set { name = value; transmissions.Refresh(); //REFRESHES WHEN CHANGED RaisePropertyChanged(() => this.Name); } }
//UI<DataGrid ItemsSource="{Binding FilterViewModel.Transmissions}"/><DataGrid.Resources><Style TargetType="DataGridRow"><Setter Property="IsEnabled" Value="{Binding IsEnabled}"/></Style></DataGrid.Resources>
public class TransmissionPresenter : Transmission { private bool isEnabled; public bool IsEnabled { get { return isEnabled; } set { isEnabled = value; RaisePropertyChanged(() => this.IsEnabled); } } }
Take a look at WPF FlashMessage
About.me