In many ways it was easier, although it took me much longer than I anticipated to get WPF right in my head and that was mostly about coming to understand the WPF design philosophy.Īs I climbed the learning curve I realised that WPF is complicated, and at times makes your head want to explode, but much of it makes good sense. I thought that using WPF would be easier than attempting it in Windows Forms. I had hardly used WPF previously and so wanted to use it for the learning experience. I created the NetworkView control for a hobby project that required graph editing. Josh Smith also has an article on MVVM and if you already know a bit of WPF and MVVM I can recommend reading Gary Hall's book, I just read it and found that it has helped progress my MVVM knowledge and experience. Christian Mosers WPF is full of interesting snippets of WPF information and has some great diagrams that can help explain WPF concepts. Josh Smith's Guided Tour of WPF and Sacha Barber's WPF: A Beginner's Guide are a good place to start if you want a WPF primer. An understanding of MVVM, WPF styles, control templates and data-templates will also help, although I'll do my best to fill in some of the details along the way and provide links to learning resources. I am going to assume that you already know C# and have at least a basic knowledge of using WPF and XAML. The main window shows a viewport onto the graph and beneath it the overview window shows the entire canvas. This screenshot shows a simple graph created in the advanced sample. Josh Smith has a great article that shows how a view-model can improve your experience with the WPF TreeView. The simple sample uses a simple view-model while the advanced sample extends the view-model and adds new features. Using a view-model is the way it is intended to be used, so this is what we will be looking at. This is similar to other WPF controls such as TreeView where you can also get by without a view-model. It is possible, though I don't recommend it, to use NetworkView programmatically or in XAML without a view-model. NetworkView is intended to be backed with an application-specific view-model. Instead, where appropriate, I'll refer back to previous articles. I won't be covering these techniques in detail here. NetworkView and the sample applications make use of all these techniques. In previous articles I have covered a number of WPF techniques: use of adorners, zooming and panning, binding to UI element positions and most recently drag-selection of multiple items. This will be useful if you want to make your own modifications to NetworkView or if you want to understand my approach to developing a complex WPF custom control.Īt the end of the article is a reference section that describes the public properties, methods and commands exposed by NetworkView. Part 2 goes into detail on the implementation. This part and the reference section are enough if you just want to use NetworkView. Part 1 examines NetworkView usage with walkthroughs of the two sample projects. This article is arranged in two main parts. The article and the sample code show how to use the control from XAML and from C# code. NetworkView, as I have called it, was inspired by and has many similarities to standard WPF controls such as ItemsControl and TreeView. This article examines the use and implementation of a WPF custom control that is used to display and edit networks, graphs and flow-charts.
0 Comments
Leave a Reply. |