public TreeViewHandler() { Control = new EtoTreeView(); var template = new sw.HierarchicalDataTemplate(typeof(ITreeItem)); template.VisualTree = WpfListItemHelper.ItemTemplate(); template.ItemsSource = new swd.Binding { Converter = new WpfTreeItemHelper.ChildrenConverter() }; Control.ItemTemplate = template; var style = new sw.Style(typeof(swc.TreeViewItem)); //style.Setters.Add (new sw.Setter (swc.TreeViewItem.IsExpandedProperty, new swd.Binding { Converter = new WpfTreeItemHelper.IsExpandedConverter (), Mode = swd.BindingMode.OneWay })); style.Setters.Add(new sw.Setter(swc.TreeViewItem.IsExpandedProperty, new swd.Binding { Path = expandedProperty, Mode = swd.BindingMode.TwoWay })); Control.ItemContainerStyle = style; ITreeItem oldSelectedItem = null; Control.CurrentItemChanged += (sender, e) => { Control.Dispatcher.BeginInvoke(new Action(() => { var newSelected = this.SelectedItem; if (oldSelectedItem != newSelected) { Widget.OnSelectionChanged(EventArgs.Empty); oldSelectedItem = newSelected; this.RefreshData(); } })); }; }
private void BuildDecisionTableItemTemplate() { FrameworkElementFactory textBlockFactory = new FrameworkElementFactory(typeof(TextBlock)); textBlockFactory.SetBinding(TextBlock.TextProperty, new Binding("Name")); DecisionTableItemTemplate = new HierarchicalDataTemplate { ItemsSource = new Binding("ConditionsActionsSubTables"), ItemTemplateSelector = this, ItemContainerStyle = DTElementItemStyle, VisualTree = textBlockFactory }; }
void SetTemplate() { var source = new swd.RelativeSource(swd.RelativeSourceMode.FindAncestor, typeof(swc.TreeViewItem), 1); template1 = new sw.HierarchicalDataTemplate(typeof(ITreeItem)); template1.VisualTree = WpfListItemHelper.ItemTemplate(LabelEdit, source); template1.ItemsSource = new swd.Binding { Converter = new WpfTreeItemHelper.ChildrenConverter() }; Control.ItemTemplate = template1; template2 = new sw.HierarchicalDataTemplate(typeof(ITreeItem)); template2.VisualTree = WpfListItemHelper.ItemTemplate(LabelEdit, source); template2.ItemsSource = new swd.Binding { Converter = new WpfTreeItemHelper.ChildrenConverter() }; }
public TemplateTheTree() { Title = "Template the Tree"; // Create TreeView and set as content of window. TreeView treevue = new TreeView(); Content = treevue; // Create HierarchicalDataTemplate based on DiskDirectory. HierarchicalDataTemplate template = new HierarchicalDataTemplate(typeof(DiskDirectory)); // Set Subdirectories property as ItemsSource. template.ItemsSource = new Binding("Subdirectories"); // Create FrameworkElementFactory for TextBlock. FrameworkElementFactory factoryTextBlock = new FrameworkElementFactory(typeof(TextBlock)); // Bind Text property with Name property from DiskDirectory. factoryTextBlock.SetBinding(TextBlock.TextProperty, new Binding("Name")); // Set this Textblock as the VisualTree of the template. template.VisualTree = factoryTextBlock; // Create a DiskDirectory object for the system drive. DiskDirectory dir = new DiskDirectory( new DirectoryInfo( Path.GetPathRoot(Environment.SystemDirectory))); // Create a root TreeViewItem and set its properties. TreeViewItem item = new TreeViewItem(); item.Header = dir.Name; item.ItemsSource = dir.Subdirectories; item.ItemTemplate = template; // Add TreeViewItem to TreeView. treevue.Items.Add(item); item.IsExpanded = true; }
private static DataTemplate CreateArchiveListingTemplate(bool hierarchical) { DataTemplate template; if (hierarchical) { //template = new HierarchicalDataTemplate {DataType = typeof(UiArchiveNodeOld)}; //((HierarchicalDataTemplate)template).ItemsSource = new Binding("OrderedHierarchyChilds"); template = new HierarchicalDataTemplate {DataType = typeof(UiContainerNode)}; ((HierarchicalDataTemplate)template).ItemsSource = new Binding("BindableHierarchyChilds"); } else { //template = new DataTemplate {DataType = typeof(UiArchiveNodeOld)}; template = new DataTemplate {DataType = typeof(UiNode)}; } FrameworkElementFactory stackPanel = new FrameworkElementFactory(typeof(StackPanel)); stackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); FrameworkElementFactory checkbox = new FrameworkElementFactory(typeof(CheckBox)); checkbox.SetValue(ToggleButton.IsCheckedProperty, new Binding("IsChecked") {Mode = BindingMode.TwoWay}); checkbox.SetValue(ToggleButton.IsThreeStateProperty, true); stackPanel.AppendChild(checkbox); FrameworkElementFactory image = new FrameworkElementFactory(typeof(Image)); image.SetValue(HeightProperty, 16d); image.SetValue(Image.SourceProperty, new Binding("Icon")); image.SetValue(MarginProperty, new Thickness(3)); stackPanel.AppendChild(image); //FrameworkElementFactory icon = new FrameworkElementFactory(typeof(ContentPresenter)); //icon.SetValue(ContentPresenter.ContentProperty, new Binding("Icon")); //icon.SetValue(MarginProperty, new Thickness(3)); //stackPanel.AppendChild(icon); FrameworkElementFactory textBlock = new FrameworkElementFactory(typeof(TextBlock)); textBlock.SetBinding(TextBlock.TextProperty, new Binding("Name")); textBlock.SetValue(MarginProperty, new Thickness(3)); stackPanel.AppendChild(textBlock); template.VisualTree = stackPanel; return template; }
/// <summary> /// Creates a new HierarchicalDataTemplate for the internal tree view /// when the property PropertyName or ChildPropertyName is changed. /// </summary> private void CreateHierarchicalDataTemplate() { var textBoxFactory = new FrameworkElementFactory(typeof(EditableTextBlock)); var template = new HierarchicalDataTemplate { ItemsSource = new Binding("Children") }; textBoxFactory.SetBinding(EditableTextBlock.TextProperty, new Binding("Name")); // set up the event handlers textBoxFactory.AddHandler(MouseDoubleClickEvent, new MouseButtonEventHandler(EditableTextBlockMouseDoubleClick)); textBoxFactory.AddHandler(KeyDownEvent, new KeyEventHandler(EditableTextBlockKeyDown)); textBoxFactory.AddHandler(MouseUpEvent, new MouseButtonEventHandler(EditableTextBlockMouseUp)); // attach the textbox to the tempaltes visual tree. template.VisualTree = textBoxFactory; // attach the template to the tree view TView.ItemTemplate = template; }
private HierarchicalDataTemplate GetTemplate() { //create the data template HierarchicalDataTemplate dataTemplate = new HierarchicalDataTemplate(); //create stack pane; FrameworkElementFactory grid = new FrameworkElementFactory(typeof(Grid)); grid.Name = "parentStackpanel"; grid.SetValue(Grid.WidthProperty, Convert.ToDouble(200)); grid.SetValue(Grid.HeightProperty, Convert.ToDouble(24)); grid.SetValue(Grid.MarginProperty, new Thickness(2)); // Create Image FrameworkElementFactory image = new FrameworkElementFactory(typeof(Image)); image.SetValue(Image.MarginProperty, new Thickness(2)); image.SetValue(Image.VerticalAlignmentProperty, VerticalAlignment.Center); image.SetValue(Image.HorizontalAlignmentProperty, HorizontalAlignment.Left); image.SetBinding(Image.SourceProperty, new Binding() { Path = new PropertyPath("ImageUrl") }); grid.AppendChild(image); // create text FrameworkElementFactory label = new FrameworkElementFactory(typeof(TextBlock)); label.SetBinding(TextBlock.TextProperty, new Binding() { Path = new PropertyPath("Title") }); label.SetValue(TextBlock.MarginProperty, new Thickness(25,2,2,2)); label.SetValue(TextBlock.FontWeightProperty, FontWeights.Bold); label.SetValue(TextBlock.ToolTipProperty, new Binding("Title")); grid.AppendChild(label); dataTemplate.ItemsSource = new Binding("Items"); //set the visual tree of the data template dataTemplate.VisualTree = grid; return dataTemplate; }
private DockPanel CreateUI() { DockPanel collision_dock_panel = new DockPanel() { LastChildFill = true }; StackPanel collision_stack_panel = new StackPanel() { HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, VerticalAlignment = System.Windows.VerticalAlignment.Stretch, }; RowDefinition tree_row = new RowDefinition(); RowDefinition splitter_row = new RowDefinition(); RowDefinition properties_row = new RowDefinition(); tree_row.Height = System.Windows.GridLength.Auto; tree_row.MaxHeight = 500; tree_row.MinHeight = 10; splitter_row.Height = System.Windows.GridLength.Auto; properties_row.Height = System.Windows.GridLength.Auto; properties_row.MinHeight = 80; Grid col_grid = new Grid(); col_grid.RowDefinitions.Add(tree_row); col_grid.RowDefinitions.Add(splitter_row); col_grid.RowDefinitions.Add(properties_row); System.Windows.HierarchicalDataTemplate template = new System.Windows.HierarchicalDataTemplate(typeof(CollisionGroupNode)); template.ItemsSource = new Binding("Children"); System.Windows.FrameworkElementFactory tb = new System.Windows.FrameworkElementFactory(typeof(TextBlock)); tb.SetBinding(TextBlock.TextProperty, new Binding("Name")); tb.SetValue(TextBlock.ForegroundProperty, Brushes.Black); template.VisualTree = tb; m_CollisionTree = new TreeView() { VerticalAlignment = System.Windows.VerticalAlignment.Stretch, HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, ItemTemplate = template }; m_CollisionTree.SelectedItemChanged += M_test_tree_SelectedItemChanged; m_CollisionTree.PreviewMouseLeftButtonDown += OnItemMouseDoubleClick; Grid.SetRow(m_CollisionTree, 0); GridSplitter splitter = new GridSplitter() { Height = 5, VerticalAlignment = System.Windows.VerticalAlignment.Top, HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch }; Grid.SetRow(splitter, 1); WDetailsView actor_details = new WDetailsView() { Name = "Details", HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, VerticalAlignment = System.Windows.VerticalAlignment.Stretch, DataContext = DetailsViewModel }; GroupBox actor_prop_box = new GroupBox() { HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, VerticalAlignment = System.Windows.VerticalAlignment.Stretch, Header = "Properties", Content = actor_details, }; Grid.SetRow(actor_prop_box, 2); col_grid.Children.Add(m_CollisionTree); col_grid.Children.Add(splitter); col_grid.Children.Add(actor_prop_box); DockPanel.SetDock(collision_stack_panel, Dock.Top); collision_stack_panel.Children.Add(col_grid); collision_dock_panel.Children.Add(collision_stack_panel); return(collision_dock_panel); }
private void BuildSelectableDecisionTableItemTemplate() { FrameworkElementFactory checkBoxFactory = new FrameworkElementFactory(typeof(CheckBox)); checkBoxFactory.SetBinding(CheckBox.IsCheckedProperty, new Binding("IsSelected")); FrameworkElementFactory textBlockFactory = new FrameworkElementFactory(typeof(TextBlock)); textBlockFactory.SetBinding(TextBlock.TextProperty, new Binding("Name")); textBlockFactory.SetValue(TextBlock.MarginProperty, new Thickness(3, 0, 0, 0)); FrameworkElementFactory stackPanelFactory = new FrameworkElementFactory(typeof(StackPanel)); stackPanelFactory.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); stackPanelFactory.AppendChild(checkBoxFactory); stackPanelFactory.AppendChild(textBlockFactory); DecisionTableItemTemplate = new HierarchicalDataTemplate { ItemsSource = new Binding("ConditionsActionsSubTables"), ItemTemplateSelector = this, ItemContainerStyle = DTElementItemStyle, VisualTree = stackPanelFactory }; }
private void BuildSubTableContainerDataTemplate() { FrameworkElementFactory textBlockFactory = new FrameworkElementFactory(typeof(TextBlock)); textBlockFactory.SetValue(TextBlock.TextProperty, "Decision Tables"); SubTableContainerDataTemplate = new HierarchicalDataTemplate { ItemsSource = new Binding("SubTables"), ItemTemplate = DecisionTableItemTemplate, ItemContainerStyle = DecisionTableItemStyle, VisualTree = textBlockFactory }; }
private void Switch() { Binding binding = new Binding("Name"); Binding pureNamebinding = new Binding("PureName"); // HierarchicalDataTemplate template = (HierarchicalDataTemplate) this.FindResource("classItemTemplate"); // HierarchicalDataTemplate explorerTemplate = (HierarchicalDataTemplate) treeView.ItemTemplate; // template = (HierarchicalDataTemplate) template.ItemTemplate; HierarchicalDataTemplate template = new HierarchicalDataTemplate(); template.ItemsSource = new Binding("Objects"); // FrameworkElementFactory factory = template.VisualTree; FrameworkElementFactory factory = new FrameworkElementFactory(typeof(TextBlock)); factory.SetBinding(TextBlock.TextProperty, binding); template.VisualTree = factory; HierarchicalDataTemplate classTemplate = new HierarchicalDataTemplate(); FrameworkElementFactory classfactory = new FrameworkElementFactory(typeof(TextBlock)); classfactory.SetBinding(TextBlock.TextProperty, pureNamebinding); classTemplate.VisualTree = classfactory; template.ItemTemplate = classTemplate; treeView.ItemTemplate = template; }