展开WPF的功能 [英] Expand the functionality of wpf

查看:106
本文介绍了展开WPF的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建它主要由一个树状视图和一个画布Visual Studio中的GUI。的应用程序的功能是最初应以后为了构造一个紧凑的单元被连接在画布上创建有些复杂形状(最终目的不是图形,而是代表函数和过程)。更具体地,用户必须通过在树视图的形状选择的可能性,画布和相应的形状上点击要绘制。他也有移动的画布上的形状,并把它们与线路连接的可能性。很明显,应用程序应该延长使用mouselisteners(mouseEvents)的。

I would like to create a GUI with Visual Studio which is composed mainly by a Treeview and a canvas. The functionality of the application is initially to create somewhat complicated shapes on the canvas which should be connected later in order to construct a compact unit (the final purpose is not graphical, but represent functions and procedures). More particularly, the user would have the possibility by a shape selection on the Treeview to click on the canvas and the respective shape to be drawn. He has also the possibility to move the shapes on the canvas and to connect them with lines. It becomes apparent that the application should make extended use of mouselisteners (mouseEvents).

是一个WPF适当类型的项目来实现类似的东西?

Is a wpf the appropriate type of project to accomplish something like that?

由于它们的形状不是简单的,但它们所包含的内容,其他形状,按钮和mouseEvents,代码为要求他们的创作不仅局限于。它应该是完全在MainWindow.xaml.cs或者倒不如直接拆分实施更多的课程(例如为每个形状单独的类)?例如矩形的代码是迄今为止:

Given that they shapes are not plain but they contain contents, other shapes, buttons and mouseEvents, the code demanded for their creation is not confined. Should it be entirely in the MainWindow.xaml.cs or it would be better directed to split the implementation to more classes (e.g. one separate class for each shape)? For example the code for the Rectangle is so far:

Double rectWidth = 100;
Double rectHeight = rectWidth;

shapeToRender = new Rectangle() { Fill = Brushes.Red, Height = 100, Width = 100, RadiusX = 7, RadiusY = 7 };
shapeToRender.Stroke = Brushes.Black;
shapeToRender.StrokeThickness = 3;
currentShape = SelectedShape.Empty;

Canvas.SetLeft(shapeToRender, e.GetPosition(canvasDrawingArea).X - rectWidth / 2);
Canvas.SetTop(shapeToRender, e.GetPosition(canvasDrawingArea).Y - rectHeight / 2);

canvasDrawingArea.Children.Add(shapeToRender);

double xCircle1 = e.GetPosition(canvasDrawingArea).X + (rectWidth)/2;
double yCircle1 = e.GetPosition(canvasDrawingArea).Y + (rectHeight)/4;
double xCircle2 = xCircle1;
double yCircle2 = e.GetPosition(canvasDrawingArea).Y - (rectWidth) / 4;
double xCircle3 = e.GetPosition(canvasDrawingArea).X - rectWidth / 2;
double yCircle3 = e.GetPosition(canvasDrawingArea).Y;

Ellipse s1Ellipse = new Ellipse() { Fill = Brushes.Yellow, Height = 10, Width = 10 };
Canvas.SetLeft(s1Ellipse, xCircle1-5);
Canvas.SetTop(s1Ellipse, yCircle1-5);

canvasDrawingArea.Children.Add(s1Ellipse);

Ellipse s2Ellipse = new Ellipse() { Fill = Brushes.Yellow, Height = 10, Width = 10 };
Canvas.SetLeft(s2Ellipse, xCircle2-5);
Canvas.SetTop(s2Ellipse, yCircle2-5);

canvasDrawingArea.Children.Add(s2Ellipse);

Ellipse s3Ellipse = new Ellipse() { Fill = Brushes.Yellow, Height = 10, Width = 10 };
Canvas.SetLeft(s3Ellipse, xCircle3 - 5);
Canvas.SetTop(s3Ellipse, yCircle3 - 5);

canvasDrawingArea.Children.Add(s3Ellipse);

是否合理建立一个单独的类,负责创建矩形?那么我怎么能操纵新类里面的主窗口的元素和mousEvents?

Is it reasonable to build a separate class that is responsible to create the rectangles? How could then I manipulate elements of the MainWindow and the mousEvents inside the new class?

推荐答案

从你写的东西WPF正是你需要的。恕我直言,你应该创建类(自定义控件)来表示您的图表项目。你没必要需要编写不同的类图上的每个形状。如果外观是所有不同的是,你总是可以使用不同的模板来改变你的图表控制的代表性。

From what you've wrote WPF is exactly what you need. IMHO you should create class (custom control) to represent your diagram items. You don't necessary need to write different class for every shape on diagram. If the look is all that is different you can always use different templates to change the representation of your diagram control.

如何建立这样的事情是相当复杂的问题。我穿过一个非常有用的文章就在WPF创建图表设计师。它实际上是一组文章。他们是开始的好地方。 这里的链接,文章的最后(因为它包含指向以前的文章)。

How to build such a thing is rather complex question. I've came across a very useful article on creating diagram designer in WPF. It is actually a set of articles. They would be a good place to start. Here's the link for the last article (because it contains links to previous articles).

这篇关于展开WPF的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆