DropDown TreeView
-
I'm trying to create a Custom Control that will be a DropDown TreeView. Basically I want to replace a comboboxe's control template with a treeview. I've tried different things, but here's what I have so far:
<Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ComboBox}"> <Border Margin="2" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{TemplateBinding BorderThickness}"> <TreeView ItemsSource="{Binding TreeData, RelativeSource ={RelativeSource TemplatedParent}}"/> </Border> </ControlTemplate> </Setter.Value> </Setter>
When I run it and drop it down, there's nothing there. Can someone please point me in the right direction?
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
-
I'm trying to create a Custom Control that will be a DropDown TreeView. Basically I want to replace a comboboxe's control template with a treeview. I've tried different things, but here's what I have so far:
<Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ComboBox}"> <Border Margin="2" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{TemplateBinding BorderThickness}"> <TreeView ItemsSource="{Binding TreeData, RelativeSource ={RelativeSource TemplatedParent}}"/> </Border> </ControlTemplate> </Setter.Value> </Setter>
When I run it and drop it down, there's nothing there. Can someone please point me in the right direction?
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
ComboBox inherits from Selector; TreeView doesn't. Maybe there's the rub. [https://stackoverflow.com/questions/722700/wpf-treeview-inside-a-combobox#:~:text=The easiest way to implement,treeview in a popup control.\](https://stackoverflow.com/questions/722700/wpf-treeview-inside-a-combobox#:~:text=The easiest way to implement,treeview in a popup control.) I've created "tree views" using everything, except using a TreeView. My latest is multiple linked FlipViews (4), with PipsPagers for each FlipView; and a final child ListView of custom controls. Super efficient for an 800+ hierarchical view (UWP).
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
ComboBox inherits from Selector; TreeView doesn't. Maybe there's the rub. [https://stackoverflow.com/questions/722700/wpf-treeview-inside-a-combobox#:~:text=The easiest way to implement,treeview in a popup control.\](https://stackoverflow.com/questions/722700/wpf-treeview-inside-a-combobox#:~:text=The easiest way to implement,treeview in a popup control.) I've created "tree views" using everything, except using a TreeView. My latest is multiple linked FlipViews (4), with PipsPagers for each FlipView; and a final child ListView of custom controls. Super efficient for an 800+ hierarchical view (UWP).
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
How would you implement this as a custom control? I know the ControlTemplate would have to be overridden, but I'm fuzzy on how to do it.
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
-
How would you implement this as a custom control? I know the ControlTemplate would have to be overridden, but I'm fuzzy on how to do it.
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
I've implemented "tree views" using a user control "around" a ListView. All my user control revolve around something; nothing ever so special that it required a "custom control" (which is more complicated). For a tree view - list view, each item is a usercontrol that can "indent" or "hide" itself (when expanding or collapsing). The item's user control has it's own data template; and that's how you can have every every item (level) look different by selectively exposing different parts of the same UC type. All that's required of the item "data container" is a level number and an "expanded / collapsed" indicator; the level number is used to compute the indent (a Margin or some other "empty" object with length). The items are of course loaded in the proper sequence (hierarchy / BOM). A selection change handler can identify what level and "node" is being accessed. An expand / collapsed method keys off the current selected item and just travels the sequence below that depth. I also added parent and child pointers (based on my needs). And added drag and drop from the (listview) tree view. On the surface, you can't tell it's a listview. Once you build one, only the item data template changes for the next "tree view". The "drop down" could be the tree view inside a ScrollViewer, inside an Expander. Or a popup. What ever works best.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I