I created a WPF steckflow project under Expression Blend 2013.
I would like to sketch a navigation tree to demonstrate how users can select items in a tree. The tree should represent categories at the first level (Cat 1, Cat 2, ...) and items should be under each category node. It should be pretty similar to the navigation tree of the Assets in Blend.
How can I sketch this tree?
Thank you
Right so what you're referring to is called a TreeView that you can find and use by going to your "Assets" tab and choosing "Controls" then selecting the TreeView and dragging it to your design surface. Then of course you'll have to add items and sub-items to it.
Hope this helps. Cheers
Related
I want to calculate enter image description here automation id of text block inside the content presenter. My visual tree looks like this-
You can use System.Windows.Media.VisualTreeHelperto determine any control in visual tree.
There are two helpful methods
System.Windows.Media.VisualTreeHelper.GetParent(DependencyObject reference)
to go up in tree hierarchy
System.Windows.Media.VisualTreeHelper.GetChiled(DependencyObject refernce, int childIndex)
to go down in tree hierarchy
See more: VisualTreeHelper
I would like to be able to display network-tree information (stored in hierarchical data structure), as in the example shown in here:
In the diagram, I have a number of hosts (top-level nodes) - one of which is considered the 'Master' and therefore rendered differently from the other top-level nodes. Each node can have multiple sub-nodes (probes). The lines between the nodes show connections and if any of the connections goes down, the line changes as shown between Hostname2 and Probe2.3. Any node selected (host or probe) should also be rendered differently.
I am using Prism/MVVM and I'm trying to keep the code as clean as possible, but I'm not sure of the best way forward for displaying this data.
I have considered using a TreeView but I cannot think of a clean way of creating the links between nodes. I also considered creating a custom panel, but I'm not sure that's the most appropriate and wouldn't know where to start. Then I thought of creating a custom ItemsControl, as it would be nice to use the DataTemplate and HierarchicalDataTemplate. I could also create a UserControl that contains a canvas and do everything in the code-behind there but it doesn't feel the best way.
I'd be grateful for opinions, example code, links or any suggestions you may have.
You're in luck, last year I had to write something very similar for my current job. I can't give you any of my code but I can lead you in the proper direction.
I found a directed graph collection class available here: http://msdn.microsoft.com/en-us/library/ms379574(v=vs.80).aspx#datastructures20_5_topic3.
I also use a Radial Panel I found on MSDN: http://msdn.microsoft.com/en-us/library/ms771363(v=VS.90).aspx. This allows multiple nodes to draw in a geometric shape. So if you have 3 nodes, they draw a triangle, 4 a square, 5 a pentagon, etc...The more nodes you have, the more the layout becomes a circle. This wouldn't work for you, but if you follow the link it shows you how to create a custom panel with a custom layout. It could be beneficial.
I then used a Canvas as the stage, with the RadialPanel as the Canvas' child element. Each node is just a WPF UserControl with an ellipses background that is added to the RadialPanel. The directed graph collection then become a collection of node view models. I store where the node is connecting, almost like a linked list. This allows me to traverse my graph collection easily without having to iterate each node to find the nodes I'm looking for.
There are some tricks involved in drawing to ensure the layout is proper, especially when drawing your connecting lines. See this StackOverflow post I made: WPF and C# - Issue with GeneralTransform and UIElement.TransformToVisual. It has a link to an image of my node graph so you can compare our graphs.
This obviously isn't everything, but I think it's a good start. For me, I couldn't really override any current controls to do exactly what I needed, so I went the hard way. The trade off is a lot of work in the code-behind and view models, but I also control the major aspects of how it's drawn. I this helps.
If in my wpf application there are multiple grids and a dragable user control.Can anyone suggest code that could return different grid id every time the control is dragged over different grids.
You can use Mouse.DirectlyOver then go up the visual tree to find the first Grid up the tree.
Mouse.DirectlyOver returns the IInputElement that is under the mouse at the time you check the property.
You can walk up the visual tree using a method described in this SO question
Edit: I found the SO question about visual tree walking i was thinking about. (much better than the first link IMHO).
I'm looking for a 2 sided winform Tree control. something like what you see in the math books. meaning that the tree can go both right and left in the control.
Something like http://www.math.bas.bg/~nkirov/2010/NETB201/slides/ch06/pic3.jpg
Thanks
Avi
You can possibly create a control for yourself deriving from the treeview and doing all the styling in the derived control. But I am sure it will be tedious thing. If you need to just show some data, in that case you can think of using SVG (its an XML inside) so that you can change data as you wish. Otherwise, think of WPF.
Does anybody know of a tutorial or sample code on how to create a simple designer control in WPF?
I am trying to write a simple designer in WPF where users can drag and drop data items (charts & lists) on specific points on a page (e.g. Line 3, Coloumn 24).
You can check out this article about a diagram designer in WPF (this is the last part but the entire series if 4 articles long). It's not related to report but might give you a starting point about how to manage items on a surface with drag'n'drop.