OK, so I'm attempting to teach myself the MVVM pattern and WPF, and I'm running into a block.
I have a ViewModel that has a "SelectedProduct" field. When that SelectedProduct field is set, I want to populate the contents of another property, "BindedLimits", by calling a long running function (It takes about 2-10 seconds depending on what product is selected). Ideally, I would like to kickoff the update in the background, and somehow display a "progress" window while this is occuring, but I can't seem to find any solid resources on how I would accomplish this, or if this is even the "right" way to be doing something like this.
Here's my ViewModel so far...
public class LimitsViewModel : PropertyChangedBase
{
private ProductFamily selectedProduct;
public ProductFamily SelectedProduct
{
get { return this.selectedProduct; }
set
{
bool runLongOperation = true;
if (value == this.selectedProduct)
{
runLongOperation = false;
}
this.SetPropertyChanged(ref this.selectedProduct, value);
if (runLongOperation)
{
this.Limits = LoadLimits();
}
}
}
private ObservableCollection<BindedLimit> limits;
public ObservableCollection<BindedLimit> Limits
{
get { return this.limits; }
set
{
this.SetPropertyChanged(ref this.limits, value);
}
}
private BindedLimit selectedLimit;
public BindedLimit SelectedLimit
{
get { return this.selectedLimit; }
set
{
this.SetPropertyChanged(ref this.selectedLimit, value);
}
}
private ObservableCollection<BindedLimit> LoadLimits()
{
// Long running stuff here
}
}