1

Topic: WPF: to Draw a block diagram - the approach

MVVM
There is a model for a block diagram which describes a dial-up from N units, and also the data that some units need to be connected a quantity .
Thus the beginning and the connection end is not an undoubted point (type - the middle of right side of the unit), and a point on the brink of the unit which depends on how the unit , and depending on configuration of the text in the unit, these points can float. That is the place cannot be calculated in advance, and it will be necessary to look upon the ambassador of rendering of the unit.
The model, naturally, knows nothing about coordinates and the sizes of units, simply contains enough information for certain intellectual "" on the side of representation which places units and draws .
In a head there is a whole lots of approaches to writing of it , but any is not pleasant to me, or there are too many questions when you start to think over implementation carefully.
While as a working variant I think for  the panel for ItemsControl, it gets access by the sizes  ContentPresenter units, itself places them as it is required. But she  does not draw, means there should be any second stage.
In general, there are ideas?

2

Re: WPF: to Draw a block diagram - the approach

Shocker. Pro;
To break tasks into two pieces of a functional.
Otherwise does not fly up.
The first is the full analog of arrows and units an ex-fur-tree.
The second without  can change model and place units without overlays and loops in arrows.
The second unit simply corrects numbers in Modeli1.
The second functional is mathematics and it is more difficult.
The first functional  users as in an ex-fur-tree.

3

Re: WPF: to Draw a block diagram - the approach

For a basis it is possible to take here it: http://www.freedevelopertutorials.com/w … -designer/
There the designer , it not absolutely that is necessary for you is presented, but partially the code it is possible .
For example, the code for arrows (communications), the element code which connects arrows, in the designer they only on edges , but personally I did also combined elements with a dial-up of fields and for each field  for an arrow as at you on , it was not difficult.
Into account ItemsControl' the question disputable, as a matter of fact, is the graph, instead of the list, probably makes sense to be inherited from Control' and as a source to set not the member list, and  the graph. And to implement interfaces for update.

4

Re: WPF: to Draw a block diagram - the approach

Petro123
I do not have questions, on mathematical algorithm of arrangement. Positioning of units simple enough, drawing of arrows too. A question where to thrust the arrangement code that actual sizes of units after the rendering, the turned out coordinates of points of start of arrows and means of drawing of these arrows were accessible to it.
: Personally to you I generally do not have any questions, will be grateful to your absence in a topic.

5

Re: WPF: to Draw a block diagram - the approach

Shocker. Pro wrote:

for  the panel for ItemsControl

Why not Panel (in particular Canvas)?

6

Re: WPF: to Draw a block diagram - the approach

Roman Mejtes;
, at the link I will look, thanks

Roman Mejtes wrote:

Into account ItemsControl' the question disputable, as a matter of fact, is the graph, instead of the list, probably makes sense to be inherited from Control' and as a source to set not the member list, and  the graph. And to implement interfaces for update.

, let us assume, , for a basis we take Canvas
Further in dynamics we create one unit, we add on Canvas
Further we force to fulfill forcedly  (as?) because without knowing the sizes of the previous unit, we do not calculate coordinate for the following
In a cycle it is added all units similarly, then we start to draw arrows.
So?

7

Re: WPF: to Draw a block diagram - the approach

refreg wrote:

Why not Panel (in particular Canvas)?

That the automatic machine to receive a collection from already N  units, instead of to create their code manually in a cycle. Well it as a variant

8

Re: WPF: to Draw a block diagram - the approach

Shocker. Pro;
What for to fulfill Render?
For calculation of the size of an element it is necessary to cause Measure () which returns in Control. DesiredSize the sizes of an element after the sizes of 1 element , we take elements 2 level and so on, and then when the sizes all are calculated, we allocate through Arrage on the panel elements.
I think as that so.  thus them it is not necessary.

9

Re: WPF: to Draw a block diagram - the approach

Roman Mejtes wrote:

what for to fulfill Render?
For calculation of the size of an element it is necessary to cause Measure () which returns in Control. DesiredSize the sizes of an element after the sizes of 1 element , we take elements 2 level and so on, and then when the sizes all are calculated, we allocate through Arrage on the panel elements.
I think as that so.  thus them it is not necessary.

In case of the panel - yes, it is clear. But you speak "to be inherited from Control'" - I this moment wanted to explain.

10

Re: WPF: to Draw a block diagram - the approach

Shocker. Pro;
Well  should comprise Canvas and ScrollViewer, as well as ItemsControl.
It is possible and ItemsControl to use, if peaks can be a little. As TreeView.
I am strong not  with PanelTemplate' and simply made Canvas as TemplateParts

11

Re: WPF: to Draw a block diagram - the approach

That is to cause UIElement. Measure () out of the panel it will be normal?
That is I inside  dynamic create ContentPresenter, I appropriate to it Content, then I request Measure () and I have the sizes for the further operation, so?

12

Re: WPF: to Draw a block diagram - the approach

ItemsControl uses ItemsPresenter. If ItemsPresenter not to use, and ItemsControl it is not necessary

13

Re: WPF: to Draw a block diagram - the approach

Shocker. Pro wrote:

I request Measure () and I have the sizes for the further operation

In Measure () it is transferred the greatest possible size,  returns wished (read minimum) the size.
Then in Arrange the valid size and position is transferred

14

Re: WPF: to Draw a block diagram - the approach

refreg wrote:

In Measure () it is transferred the greatest possible size,  returns wished (read minimum) the size.
Then in Arrange the valid size and position

I is transferred I know as two-flow configuration works. I ask, whether normally it to use out of the panel.

15

Re: WPF: to Draw a block diagram - the approach

Shocker. Pro wrote:

it is passed...
I know as two-flow configuration works. I ask, whether normally it to use out of the panel.

I do not see hindrances to call Measure (), or, litter, did not understand a question.

16

Re: WPF: to Draw a block diagram - the approach

refreg wrote:

I do not see hindrances to call Measure (), or, litter, did not understand a question.

well , I simply did not meet application out of the panel, suddenly there are nuances.
Roman Mejtes
And still a question - how easier to calculate absolute coordinates (for Canvas) anchor points of the beginning of an arrow?
- I put points in a unit template in a type, for example,  with a specific name or a tag or still somehow.
They there somewhere are built by means of alignments and so forth in proper places.
Further, after arrangement of units I search for points by means of LogicalTreeHelper. FindLogicalNode or GetChildren.
Further I calculate the relative position with the help

Point relativePoint = myVisual. TransformToAncestor (rootVisual).Transform (new Point (0, 0));

So? Or it is possible is easier?

17

Re: WPF: to Draw a block diagram - the approach

Shocker. Pro;
At you it turned out to understand with a question? Simply most it is interesting

18

Re: WPF: to Draw a block diagram - the approach

Well as a result I made as initially planned. All necessary VM units and VM  are showered in List <object>. In representation for display it is used ItemsControl in which it is used  the panel. The panel gets access to visual elements and through them - to necessary properties VM of units and arrows. Knowing the sizes of units and the data from models of units, the panel places all in proper places.