How to draw lines across cells in a WPF Grid - wpf

I am trying to fill the Grid control with custom controls dynamically. After the grid is filled with elements, I need to connect these elements by lines. How do I achieve this....
Thanks in advance

I have an idea you could try: Within a Grid, items will overlap each other. So you could create an outer Grid which contains your grid and also a Canvas with a transparent background. On the Canvas, you could draw lines which would look like they are connecting your Grid's elements.

You can use a Grid set as an ItemsPanel for an ItemsControl. It's not quite easy, but if that's the way you want to go.
For connecting elements by a line, here is a good article that shows you just that:
UI Frontiers: Thinking Outside the Grid (by Charles Petzold)

Related

WPF Grid Lines show across childrent element with span > 1

Are there any way to make grid to not show over grid children?
I mean, I want grid lines to be visible, but when a children has rowspan or columnspan over 1, I want it to hide the grid lines.
I tried setting the children (it's a label) opacity to 1 but it didn't work.
Any help will be welcome.
No there is not. From MSDN:
Only dotted lines are available because this property is intended as a design tool to debug layout problems and is not intended for use in production quality code. If you want lines inside a Grid, style the elements within the Grid to have borders.

Container with shape like circle lines border and textblock

I am creating grid dynamically and adding 200 rows and 240 columns and adding stackpanel at each position of the grid So totally i am drawing 4800 stackpanels .Now i want to add lines circle and 3 text blocks in each of the stackpanel
Till I am adding grid add stackpanel it working fine and rendering all controls within 4 seconds which is okay .But as i started adding text block as a child control in scakpanel it taking too much time . Should I use any other better and light weight control . Or instead of adding text block can use DrawText on show text in stack panel. I further want to use drag drop functionality for stack panel so i must use only container will move along with its child elements
I think you can avoid adding the columns and the rows phase, instead of using a Grid you can simply use a canvas and handle the tabular view (rows and columns) from your code behind using the the Left and Top properties.
Beside, a canvas will be convenient to use the drag and drop functionnality. you can use for that the MouseDragElementBehavior. but then you have to deal with absolute positioning according to your Parent Window rather then the Top and Left Properites. It still realtively easy to do.
If you're using a large view where there is only a part of it displayed, you can load only the part in view.
I Hope this will be helpfull.

WPF Ellipse why can I not add a grid?

I have a WPF application. I am trying to create a ellipse toggle button. I wanted to have a textbox in the ellipse with two images next to each other below the textbox. In my other buttons I have added a grid with two rows to achieve this.
However it doesn't like it when I try to add a grid to an ellipse. "The type ellipse does not support direct content". What does this mean? Is it possible to do what I wish?
This particular error really couldn't be too much clearer:
The type Ellipse does not support direct content.
The Ellipse Shape is not a ContentControl. Therefore, it does not have a Content property. This means that you cannot add any content to it.
What you can do is to add a Grid with no columns or rows defined and add your Ellipse into the Grid. Then you can overlay other UI elements in front of the Ellipse, which may appear as if they were inside it.

Silverlight zindex with dynamically added controls

I have grid with some textboxes and an image which goes out of grid boundaries and I add this grids dynamically in my code to another grid.
I want to have my image on top of all the rest of the grids. Unfortunately each grid I add to the root grid will hover over my previous grid image.
Could you please suggest anything?! I have tried with zindex and it did not work in my case.
What I am doing wrong?
ZIndex only works for the immediate children of a panel-derived container (Grid, Canvas, Stackpanel etc). Otherwise it is down to the order they exist in the visual tree (i.e. the last one gets displayed on top).
If you have nested objects you simply need to think about the order they are added. The simplest way to do this is have two top level grids/panels, the first contains everything else and the last containing just the dynamically added children.
This way whatever you put in the second grid will always be on top of all other items (in the first grid/container).

WPF Grid Question, can I determinate the absolute position of something, which is positioned automatically in a WPF Grid?

I like to use a grid to position some objects in WPF, because it cares about the position and stuff. In addition, however I also like to be able to draw accross the cells with a Canvas.
I figured out that this can be done by embedding the grid in a canvas. However in order to connect two elements, I need then the absolute position in pixels.. any ideas?
From code you can use the UIElement.TranslatePoint() method.

Resources