private void UserControl_Loaded(object sender, RoutedEventArgs e) { // save data context var dc = IndividualDataContext.CreateDataContext(this.DataContext); if (dc == null) { return; } // first update this.theViewModel.StoredReference = dc.refElem?.value; UpdateDisplay(); // attach lambdas for clear ButtonClear.Click += (object sender5, RoutedEventArgs e5) => { dc.instance.Touch(); dc.refElem.value = null; this.theViewModel.StoredReference = dc.refElem.value; }; // attach lambdas for select ButtonSelect.Click += (object sender6, RoutedEventArgs e6) => { // TEST //// dc.refElem.value = new AdminShellV20.Reference(new AdminShell.Key(AdminShell.Key.GlobalReference, true, AdminShell.Identification.IRI, "http://ccc.de")); //// UpdateDisplay(); // try find topmost instance var top = FormInstanceHelper.GetTopMostParent(dc.instance); var topBase = top as FormInstanceBase; if (topBase != null && topBase.outerEventStack != null) { // give over to event stack var ev = new AasxIntegrationBase.AasxPluginResultEventSelectAasEntity(); ev.filterEntities = AdminShell.Key.AllElements; ev.showAuxPackage = true; ev.showRepoFiles = true; topBase.outerEventStack.PushEvent(ev); // .. and receive incoming event topBase.subscribeForNextEventReturn = (revt) => { if (revt is AasxPluginEventReturnSelectAasEntity rsel && rsel.resultKeys != null) { dc.instance.Touch(); dc.refElem.value = AdminShell.Reference.CreateNew(rsel.resultKeys); this.theViewModel.StoredReference = dc.refElem.value; } }; } }; }
public void UpdateDisplay() { // access var inst = this.DataContext as FormInstanceListOfSame; var desc = inst?.workingDesc as FormDescSubmodelElement; if (inst == null || desc == null || GridOuterElement == null || GridInner == null) { return; } // obligatory this.TextBlockFormTitle.Text = "" + desc.FormTitle; this.TextBlockFormInfo.Text = "" + desc.FormInfo; this.TextBlockFormInfo.Visibility = (this.TextBlockFormInfo.Text.Trim() != "") ? Visibility.Visible : Visibility.Collapsed; // url link ButtonFormUrl.Visibility = Visibility.Hidden; if (desc.FormUrl != null && desc.FormUrl.Length > 0) { ButtonFormUrl.Visibility = Visibility.Visible; ButtonFormUrl.Click += (object sender3, RoutedEventArgs e3) => { // try find topmost instance var top = FormInstanceHelper.GetTopMostParent(inst); var topBase = top as FormInstanceBase; if (topBase != null && topBase.outerEventStack != null) { // give over to event stack var evt = new AasxPluginResultEventDisplayContentFile(); evt.fn = desc.FormUrl; evt.preferInternalDisplay = true; topBase.outerEventStack.PushEvent(evt); } }; } // (re-) create rows GridInner.Children.Clear(); GridInner.RowDefinitions.Clear(); int ri = 0; foreach (var si in inst.SubInstances) { if (si?.subControl != null) { // row var rd = new RowDefinition(); rd.Height = GridLength.Auto; GridInner.RowDefinitions.Add(rd); // have the control itself var sc = si.subControl; Grid.SetRow(sc, ri); Grid.SetColumn(sc, 0); GridInner.Children.Add(sc); if (this.showButtonsMinus) { // make a button like the "-" var bt = CreateButtonLike(ButtonInstancePlus, content: "➖"); bt.VerticalAlignment = VerticalAlignment.Top; bt.Content = "\u2796"; if (inst.workingDesc != null && inst.workingDesc is FormDescSubmodelElementCollection) { bt.Margin = new Thickness( bt.Margin.Left, bt.Margin.Top + 6, bt.Margin.Right, bt.Margin.Bottom); } bt.SetBinding( Button.WidthProperty, CreateBindingWithElementName("ActualWidth", "ButtonInstancePlus")); bt.SetBinding( Button.HeightProperty, CreateBindingWithElementName("ActualHeight", "ButtonInstancePlus")); // remeber the instances var masterInst = inst; var subInst = si; // attach the lambda bt.Click += (object sender, RoutedEventArgs e) => { if (inst.SubInstances.Count > this.minRows) { // carefully delete try { masterInst.SubInstances.Remove(subInst); } catch (Exception ex) { AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex); } // redraw UpdateDisplay(); } }; Grid.SetRow(bt, ri); Grid.SetColumn(bt, 1); GridInner.Children.Add(bt); } else { // give the subcontrol a little more room Grid.SetColumnSpan(sc, 2); } // next row ri++; } } }