C
C#5mo ago
Elio

✅ WPF IEnumerable PropertyChanged()

Hi, Any idea why my IEnumerable variable isn't refreshed even when the Onpropertychanged is triggered ? Here is the code : https://paste.mod.gg/xucezzpuabkj/3 note that the viewmodel is correctly bind to the view.
BlazeBin - xucezzpuabkj
A tool for sharing your source code with the world!
2 Replies
Chiyoko_S
Chiyoko_S5mo ago
shouldn't it be ObservableCollection? oh never mind
Elio
Elio5mo ago
if i do something like this, the code work but i don't understand why i should do it this way
public class ListingThicknessViewModel : ViewModelBase
{
public ThicknessStore TTThicknessStore { get; }

public IEnumerable<ThicknessViewModel>? Thicknesses => _thicknessStore.Thicknesses; // or Observable that it will do the same result

public ListingThicknessViewModel(ThicknessStore thicknessStore)
{
TTThicknessStore = thicknessStore;
_thicknessStore.PropertyChanged += OnThicknessStorePropertyChanged;
}
private void OnThicknessStorePropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if(e.PropertyName == nameof(ThicknessStore.Thicknesses) ||
e.PropertyName == nameof(MaterialStore.CurrentMaterial))
{
OnPropertyChanged(nameof(Thicknesses));
}
}
}
public class ListingThicknessViewModel : ViewModelBase
{
public ThicknessStore TTThicknessStore { get; }

public IEnumerable<ThicknessViewModel>? Thicknesses => _thicknessStore.Thicknesses; // or Observable that it will do the same result

public ListingThicknessViewModel(ThicknessStore thicknessStore)
{
TTThicknessStore = thicknessStore;
_thicknessStore.PropertyChanged += OnThicknessStorePropertyChanged;
}
private void OnThicknessStorePropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if(e.PropertyName == nameof(ThicknessStore.Thicknesses) ||
e.PropertyName == nameof(MaterialStore.CurrentMaterial))
{
OnPropertyChanged(nameof(Thicknesses));
}
}
}