示例#1
0
        private async void OnVariationsChanged(object sender, EventArgs e)
        {
            using (await AsyncWork.RequestAsyncWork(this)) {
                PropertyViewModel pvm = (PropertyViewModel)sender;
                var variations        = (await GetVariationsAsync(pvm.Property)).SelectMany(vs => vs).Distinct();
                var properties        = this.editors
                                        .OfType <PropertyViewModel> ()
                                        .Where(evm => Equals(evm.Property, pvm.Property) && evm.Variation != null)
                                        .ToDictionary(evm => evm.Variation);

                List <PropertyViewModel> toAdd = new List <PropertyViewModel> ();
                foreach (PropertyVariation variation in variations)
                {
                    if (!properties.Remove(variation))
                    {
                        toAdd.Add(GetViewModel(pvm.Property, variation));
                    }
                }

                if (properties.Count > 0)
                {
                    var toRemove = new List <PropertyViewModel> ();
                    foreach (var kvp in properties)
                    {
                        toRemove.Add(kvp.Value);
                    }

                    RemoveProperties(toRemove);
                }

                if (toAdd.Count > 0)
                {
                    AddProperties(toAdd);
                }
            }
        }
        private async void OnVariantsChanged(object sender, EventArgs e)
        {
            IPropertyInfo property = sender as IPropertyInfo;

            if (property == null)
            {
                property = ((PropertyViewModel)sender).Property;
            }

            using (await AsyncWork.RequestAsyncWork(this)) {
                var variationsTask = GetVariationsAsync(property);

                PropertyViewModel baseVm = null;
                var properties           = new Dictionary <PropertyVariation, PropertyViewModel> ();
                foreach (PropertyViewModel pvm in this.editors.OfType <PropertyViewModel> ())
                {
                    if (!Equals(property, pvm.Property))
                    {
                        continue;
                    }

                    if (pvm.Variation == null)
                    {
                        baseVm = pvm;
                    }
                    else
                    {
                        properties.Add(pvm.Variation, pvm);
                    }
                }

                if (baseVm == null)
                {
                    throw new InvalidOperationException("Base property view model couldn't be found");
                }

                var variations = await variationsTask;
                baseVm.HasVariantChildren = variations.Count > 0;

                List <PropertyViewModel> toAdd = new List <PropertyViewModel> ();
                foreach (PropertyVariation variation in variations)
                {
                    if (!properties.Remove(variation))
                    {
                        toAdd.Add(CreateViewModel(property, variation));
                    }
                }

                if (properties.Count > 0)
                {
                    var toRemove = new List <PropertyViewModel> ();
                    foreach (var kvp in properties)
                    {
                        toRemove.Add(kvp.Value);
                    }

                    RemoveProperties(toRemove);
                }

                if (toAdd.Count > 0)
                {
                    AddProperties(toAdd);
                }
            }
        }
 /// <summary>
 /// Gets whether the <paramref name="viewModel"/> is the last-arranged variant property of its base property
 /// </summary>
 internal virtual bool GetIsLastVariant(PropertyViewModel viewModel)
 {
     throw new NotSupportedException();
 }