protected override void OnNavigatedFrom(NavigationEventArgs e) { base.OnNavigatedFrom(e); if (this.demoFrame.Content is FrameworkElement frameworkElement) { if (this.demoFrame.Content is IDisposable disposableObject) { disposableObject.Dispose(); } this.demoFrame.Content = null; var demoLayouts = LogicalTree.FindChildren <DemoLayout>(frameworkElement); if (demoLayouts != null) { foreach (var demoLayout in demoLayouts) { demoLayout.HeaderText = null; demoLayout.Example = null; demoLayout.Options = null; demoLayout.Xaml = null; demoLayout.XamlSource = null; demoLayout.CSharp = null; demoLayout.CSharpSource = null; demoLayout.Substitutions.Clear(); } } } this.demoFrame.Content = null; this.DataContext = null; GC.Collect(); }
protected override void OnNavigatedTo(NavigationEventArgs e) { this.DataContext = e?.Parameter; if (this.DataContext != null) { var dataContext = this.DataContext as MainViewModel; this.DispatcherQueue.TryEnqueue(() => { if (dataContext.DemoInfo?.DemoView != null) { demoFrame.Navigate(dataContext.DemoInfo.DemoView); } if (this.demoFrame.Content is FrameworkElement frameworkElement) { var demoLayouts = LogicalTree.FindChildren <DemoLayout>(frameworkElement); if (demoLayouts != null) { Enum.TryParse(typeof(ElementTheme), dataContext.CurrentTheme.ToString(), out object theme); foreach (var demoLayout in demoLayouts) { demoLayout.CopyButtonVisibility = string.IsNullOrEmpty(demoLayout.Xaml) && string.IsNullOrEmpty(demoLayout.XamlSource) && string.IsNullOrEmpty(demoLayout.CSharp) && string.IsNullOrEmpty(demoLayout.CSharpSource) ? Visibility.Collapsed : Visibility.Visible; demoLayout.ExampleContainer.RequestedTheme = (ElementTheme)theme; } } } }); } base.OnNavigatedTo(e); }
private bool GetDcFromFrameworkElement(object feOrFce, out object dc, out Type type, out ObservableSourceStatusEnum status) { bool found = LogicalTree.GetDcFromFrameworkElement(feOrFce, out dc, out type); status = Status.SetReady(dc != null); return(found); }
public WPFButtonBase GetButton(string buttonCaption) { var btn = LogicalTree.ByType <Button>().ByContentText <Button>(buttonCaption).Single(); if (btn == null) { return(null); } return(new WPFButtonBase(btn)); }
public TestDriver(WindowControl w) { MainWindow = w; LogicalTree = w.LogicalTree(); cmbMode = new WPFComboBox(LogicalTree.ByType <ComboBox>().Single()); txtInputText = new WPFTextBox(LogicalTree.ByType <TextBox>().Single()); grdHiragana = new WPFGrid(w.AppVar["FindName"].Invoke("grdHiragana")); grdKatakana = new WPFGrid(w.AppVar["FindName"].Invoke("grdKatakana")); }
private bool UpdateData_Dg(DataGridColumn dgc, string pathElement, string binderName) { if (SourceKind != SourceKindEnum.DataGridColumn) { throw new InvalidOperationException($"Cannot call {nameof(UpdateData_Dg)} " + $"if the ObservableSource is not of SourceKind: {nameof(SourceKindEnum.DataGridColumn)}."); } System.Diagnostics.Debug.WriteLine($"Fetching DataGrid for a DataGridColumn for {pathElement}."); DataGrid dataGrid = LogicalTree.GetDataGridOwner(dgc); Type newType = dataGrid?.GetType(); ObservableSourceStatusEnum newStatus = Status.SetReady(dataGrid != null); bool changed = UpdateData(dataGrid?.SelectedItems, newType, newStatus); return(changed); }
private bool UpdateWatcherAndData_Fe(DependencyObject targetObject, string pathElement, bool isTargetADc, string binderName) { if (SourceKind != SourceKindEnum.FrameworkElement && SourceKind != SourceKindEnum.FrameworkContentElement) { throw new InvalidOperationException($"Cannot call {nameof(UpdateWatcherAndData_Fe)} " + $"if the ObservableSource does not have a SourceKind of {nameof(SourceKindEnum.FrameworkElement)} " + $"or {nameof(SourceKindEnum.FrameworkContentElement)}."); } string fwElementName = LogicalTree.GetNameFromDepObject(targetObject); System.Diagnostics.Debug.WriteLine($"Fetching DataContext to use from: {fwElementName} for pathElement: {pathElement}."); this.IsTargetADc = isTargetADc; // If this binding sets a DataContext, watch the TargetObject's parent, otherwise watch the TargetObject for DataContext updates // TODO: May want to make sure that the value of Container is a DependencyObject. DependencyObject curContainer = (DependencyObject)Container; DependencyObject newContainer = isTargetADc ? LogicalTreeHelper.GetParent(targetObject) : targetObject; if (!object.ReferenceEquals(curContainer, newContainer)) { SubscribeTo_FcOrFce(newContainer, DataContextChanged_Fe); Container = newContainer; } // Now see if we can find a data context. DependencyObject foundNode = LogicalTree.GetDataContext(targetObject, out bool foundIt, startWithParent: isTargetADc, inspectAncestors: true, stopOnNodeWithBoundDc: true); if (!foundIt) { bool changed = UpdateData(null, null, ObservableSourceStatusEnum.NoType); return(changed); } if (!object.ReferenceEquals(targetObject, foundNode)) { string foundFwElementName = LogicalTree.GetNameFromDepObject(foundNode); System.Diagnostics.Debug.WriteLine($"Found DataContext to watch using an ancestor: {foundFwElementName} for pathElement: {pathElement}."); } else { System.Diagnostics.Debug.WriteLine($"Found DataContext to watch on the target object for pathElement: {pathElement}."); } DependencyObject foundNodeWithBoundDc = LogicalTree.GetDataContextWithBoundDc(targetObject, out bool foundOneWithBoundDc, startWithParent: isTargetADc); if (foundOneWithBoundDc) { System.Diagnostics.Debug.WriteLine("Some parent has a DataContext that is set via a Binding Markup."); } if (foundNode is FrameworkElement fe) { Type newType = fe.DataContext?.GetType(); ObservableSourceStatusEnum newStatus = Status.SetReady(fe.DataContext != null); bool changed = UpdateData(fe.DataContext, newType, newStatus); //if(newType.IsIListSource()) //{ // changed = UpdateData(((IListSource)fe.DataContext).GetList(), newType, newStatus); //} //else //{ // changed = UpdateData(fe.DataContext, newType, newStatus); //} return(changed); } else if (foundNode is FrameworkContentElement fce) { Type newType = fce.DataContext?.GetType(); ObservableSourceStatusEnum newStatus = Status.SetReady(fce.DataContext != null); bool changed = UpdateData(fce.DataContext, newType, newStatus); return(changed); } else { throw new ApplicationException($"Found node in {binderName}.ObservableSourceProvider was neither a FrameworkElement or a FrameworkContentElement."); } }