MVVM : Injecting INotifyPropertyChanged Into an Existing Class

יום שישי, דצמבר 10, 2010

Download the source code for this post here. Using MVVM in Silverlight and WPF I often encounter the following problem. I have a business class that needs to be exposed through the ViewModel. For this, it needs to implement INotifyPropertyChanged or expose Dependency properties. I take the side of those who prefer to keep WPF dependencies out of the ViewModel, so I usually take the path of writing a proxy that delegates properties to the business object and implementing INotifyPropertyChanged. I am not comfortable with this duplication, and I usually pay a price for it when I refactor the business class, but I...
תגיות: , , , ,
2 תגובות

How to Bind to the Index of a Collection in WPF

יום שבת, אפריל 17, 2010

Let's say you have a customer class and you are binding a DataGrid to a collection of customers. You would like the index of the customer in the collection to appear in the first column, like so: One way to do this might be to add an Index property to the Customer class and bind to that. I prefer not to go that way because it would pollute our business layer with presentation layer constraints. Solution Here is a different approach using a MultiBinding. You can download the source...
תגיות: , ,
3 תגובות

Hierarchical Grid with WPF

A TreeView handles hierarchical data well, and a DataGrid handles tabular data. But what about hierarchical tabular data? A simple example of such a source is a System.IO.DirectoryInfo. Each item can have zero or more children of the same type, enumerated by EnumerateDirectories. I would like to have it displayed like this: Solution You can download the source code for this solution here. The inspiration for this solution came from Delay's Blog by David Anson. I think David's idea of measuring the indentation at each level and compensating for it in...
תגיות: , , ,
8 תגובות

Windows 7 and WPF 4 at Developer Academy 4

יום שני, מרץ 22, 2010

Today at Developer Academy I gave a demonstration session called Capture the Windows 7 User Experience with Windows Presentation Foundation 4. In the demo I showed how to integrate the following Windows 7 taskbar features into Windows applications using WPF 4: Specifying the area of the application visible in the Thumbnail Preview Controlling the Progress Bar overlay in the Task Bar Adding Taskbar Buttons to an application on the Task Bar Adding Icon Overlays Adding Jump List items to the context menu...
אין תגובות

Mapping MediaElement onto a Sphere with WPF

יום שני, יוני 29, 2009

In my previous post I created a 3D cube, mapped a MediaElement onto each of its faces and animated the camera around the cube. In this post, I will replace the 3D cube with a sphere and wrap the video onto the surface of the sphere. I omit the camera animation for simplicity, but you can add it back, of course. You can download the source code here. In order to create the sphere mesh I made use of Charles Petzold’s elegant SphereMeshGenerator. In Chapter 6 of his book (3D Programming for Windows: Three-Dimensional Graphics Programming for the Windows Presentation Foundation) Petzold...
תגיות: , , , ,
תגובה אחת

A Custom Animation Class – Point3DAnimationUsingPath

יום ראשון, יוני 21, 2009

For 2D graphics WPF provides three classes for animating points: PointAnimation (for linear interpolation), PointAnimationUsingKeyFrames and PointAnimationUsingPath. For 3D graphics WPF provides only two: Point3DAnimation (for linear interpolation) and Point3DAnimationUsingKeyFrames. There is no built in class for animating points over a path in three dimensions. In this post I will show you a custom animation class that I wrote to partially fill that gap. In the next post I will put it to use in a 3D animation demo. Requirement Provide an animation class that enables the animation of a 3D point over a 3D...
תגיות: , , ,
2 תגובות

TreeView DataBinding and The Composite Pattern

יום שישי, יוני 5, 2009

In the previous post I demonstrated use of the HierarchicalDataTemplate to style nodes based on the type of the object that they are bound to. That declarative recursion gets you true separation between data and presentation. In this post, I will show how I made use of the Composite Pattern, INotifyPropertyChanged and BindingSource<T> to implement objects for DataBinding with the TreeView. In the next post I will show how I used LINQ to XML to read the data from an XML file. The Composite Pattern In the example at hand, HierarchicalDataTemplate is able to apply...
אין תגובות

WPF, Windows Forms and ATL Part 3

יום שני, מאי 25, 2009

Continued from Part 2. So now for the second scenario. Hosting WPF controls in legacy containers. Well let’s start with hosting a WPF control in a Windows Form. Then we’ll have a bash at hosting a WPF control in an unmanaged application (hee, hee). Here is the source code for the three projects described in this post. Hosting WPF Controls in a Windows Form Hosting WPF Controls in a Windows Forms application is quite straightforward. The key is the ElementHost control in the Systems.Windows.Forms.Integration namespace which is a Windows Forms Control and can reference any...
תגיות: , , , ,
אין תגובות

WPF, Windows Forms and ATL Part 2

Continuing from Part 1. We are still discussing the first scenario for WPF Interop, namely using COM and Windows Forms User Controls in a WPF application. Here I will be giving some examples. In the next post I will discuss the second scenario – hosting a WPF control in a Windows Form application. You can download all the source code for Part 1 and Part 2 of this article here. Please note: All projects were prepared with Visual Studio 2010 Beta 1. WPF Application using a Simple COM Object (ATL) I used ATL...
תגיות: , , , ,
אין תגובות

WPF, Windows Forms and ATL Part 1

OK. I finally managed to create the sample ATL called Polygon from the ATL Tutorial on MSDN using the Visual Studio 2010 Beta 1. The problems I mention in the previous post remain; I simply hand-coded the text that the ATL wizard failed to create (well, maybe simply is not appropriate here). Anyway, back to interop. We have two scenarios to examine: WPF using COM objects and Windows Forms User Controls Windows Forms using WPF controls Let’s start with the first. In the...
תגיות: , , , ,
תגובה אחת