protected async Task AddToFalloAlCargarMultiBindingsAsync(aVMTabBase newTab, FalloAlCargarUC UC) { MultiBinding falloMultiBinding = BindingOperations.GetMultiBindingExpression(UC, FalloAlCargarUC.VisibilityProperty).ParentMultiBinding; falloMultiBinding.Bindings.Add(new Binding() { Source = newTab, Path = new PropertyPath("TaskCargando.IsNotCompleted"), Mode = BindingMode.OneWay }); SetVisibilityConverter(falloMultiBinding, "FalseCollapsed"); falloMultiBinding.NotifyOnSourceUpdated = true; UC.SetBinding(FalloAlCargarUC.VisibilityProperty, falloMultiBinding); falloMultiBinding = BindingOperations.GetMultiBindingExpression(UC, FalloAlCargarUC.MensajeFalloProperty).ParentMultiBinding; falloMultiBinding.Bindings.Add(new Binding() { Source = newTab, Path = new PropertyPath("TaskCargando.ErrorMessage"), Mode = BindingMode.OneWay }); SetVisibilityConverter(falloMultiBinding); falloMultiBinding.NotifyOnSourceUpdated = true; UC.SetBinding(FalloAlCargarUC.MensajeFalloProperty, falloMultiBinding); }
private void ItemsSource_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Reset) { this.ItemsSourceProperty.Clear(); } if (e.NewItems != null) { foreach (aVMTabBase item in e.NewItems) { this.ItemsSourceProperty.Add(item); item.ChangeTabIndex(e.NewStartingIndex); FalloAlCargarUC UC = this.RootTabControl.FindVisualChild <FalloAlCargarUC>(x => (x as FrameworkElement).Name == "FalloAlCargarUC"); Task.Run(() => AddToFalloAlCargarMultiBindingsAsync(item, UC)).Forget().ConfigureAwait(false); } } if (e.OldItems != null) { foreach (VMTabDiario item in e.OldItems) { this.ItemsSourceProperty.RemoveAt(e.OldStartingIndex); FalloAlCargarUC UC = this.RootTabControl.FindVisualChild <FalloAlCargarUC>(x => (x as FrameworkElement).Name == "FalloAlCargarUC"); Task.Run(() => RemoveBindingFromFalloalCargarAsync(item, UC)).Forget().ConfigureAwait(false); } } }
protected async Task RemoveBindingFromFalloalCargarAsync(aVMTabBase removedTab, FalloAlCargarUC UC) { MultiBinding falloMultiBinding = BindingOperations.GetMultiBindingExpression(UC, FalloAlCargarUC.VisibilityProperty).ParentMultiBinding; var bindingsToRemove = falloMultiBinding.Bindings.Where(binding => ((Binding)binding).Source == removedTab); foreach (BindingBase binding in bindingsToRemove) { falloMultiBinding.Bindings.Remove(binding); } }