private C1TreeViewItem FindItem(C1HierarchicalPresenter tree, FeatureDescription feature) { var treeViewItem = tree.ItemContainerGenerator.ContainerFromItem(feature) as C1TreeViewItem; if (treeViewItem != null) { return(treeViewItem); } else { foreach (var item in tree.Items) { var tvi = tree.ItemContainerGenerator.ContainerFromItem(item) as C1TreeViewItem; if (tvi != null && tvi.HasItems) { treeViewItem = FindItem(tvi, feature); if (treeViewItem != null) { return(treeViewItem); } } } } return(null); }
protected void OnNavigatedFrom(NavigationEventArgs e) { FeatureDescription feature = DataContext as FeatureDescription; if (feature != null) { IDisposable disposable = feature.Sample as IDisposable; if (disposable != null) { disposable.Dispose(); } } }
public void OnNavigatedTo(string fragment) { fragment = "/" + Uri.UnescapeDataString(fragment); var args = fragment.Split('/'); FeatureDescription feature = null; if (args.Length > 1) { var control = MainViewModel.Instance.Controls.FirstOrDefault(c => c.Name.Equals(args[1])); if (control != null) { feature = control.GetAllFeatures().FirstOrDefault(f => f.Link.OriginalString == fragment); } } else { feature = MainViewModel.Instance.Features.FirstOrDefault(f => f.Link.OriginalString == fragment); } if (feature.SubFeatures.Count != 0) { FeatureDescription toSelect = feature.SubFeatures[0]; foreach (var f in feature.SubFeatures) { if (f.IsNew) { toSelect = f; } } feature.IsExpanded = true; feature = toSelect; } if (feature != null) { try { Title = feature.Control.Name + " - " + feature.Name; var assembly = Assembly.LoadFrom(feature.AssemblyName); feature.Sample = assembly.CreateInstance(feature.FullDemoControlTypeName) as FrameworkElement; properties.AvailableEditors.Insert(0, new TimeSpanEditor()); properties.AvailableEditors.Insert(0, new NumericEditor()); properties.AvailableEditors.Insert(0, new ReadOnlyImageSourceEditor()); properties.AvailableEditors.Insert(0, new CornerRadiusEditor()); properties.PropertyAttributes.Clear(); LoadCollection <PropertyAttribute>(properties.PropertyAttributes, feature.Properties); DataContext = feature; if (feature.Sample == null) { code.ContainsSample = false; } else { code.ContainsSample = true; code.Source = feature.Source; } Dispatcher.BeginInvoke(new Action(() => { this.UpdateLayout(); var mask = properties.SelectedObject as BasicControls.DemoMaskedTextBox; if (mask != null) { foreach (PropertyBox box in properties.PropertyBoxes) { if (box.CurrentEditor != null && box.CurrentEditor is StringEditor && box.PropertyAttribute.DisplayName == "Text") { TextBox txt = box.CurrentEditor as TextBox; txt.PreviewTextInput += txt_PreviewTextInput; txt.TextChanged += txt_TextChanged; break; } } } var item = FindItem(tree, feature); if (item != null) { item.IsSelected = true; IList <DependencyObject> list = new List <DependencyObject>(); VTreeHelper.GetChildrenOfType(tree, typeof(ScrollViewer), ref list); if (list.Count > 0) { ScrollViewer scv = list[0] as ScrollViewer; Point point = item.TransformToVisual(scv).Transform(new Point(scv.HorizontalOffset, scv.VerticalOffset)); Rect rect = new Rect(point, new Point(point.X + item.ActualWidth, point.Y + item.ActualHeight)); if (scv.VerticalOffset > rect.Top) { scv.ScrollToVerticalOffset(rect.Top); } else if (scv.VerticalOffset < rect.Bottom - scv.ViewportHeight) { scv.ScrollToVerticalOffset(rect.Bottom - scv.ViewportHeight); } } } }), System.Windows.Threading.DispatcherPriority.Loaded); } catch (Exception exc) { if (exc.InnerException != null && exc.InnerException.Message != null && exc.InnerException.Message.Contains(ControlExplorer.Properties.Resources.SamplePage_ExceptionText)) { Dispatcher.BeginInvoke(new Action(() => { MessageBox.Show(ControlExplorer.Properties.Resources.SamplePage_MsgBoxText); }), null); } if (NavigationService.CanGoBack) { NavigationService.GoBack(); } } } }