DCSIMG
WPF - David Sackstein's Blog

Browse by Tags

All Tags » WPF (RSS)

MVVM : Injecting INotifyPropertyChanged Into an Existing Class by David Sackstein

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...

How to Bind to the Index of a Collection in WPF by David Sackstein

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 code for this...
תגים:, ,

Hierarchical Grid with WPF by David Sackstein

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...

Windows 7 and WPF 4 at Developer Academy 4 by David Sackstein

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...

Mapping MediaElement onto a Sphere with WPF by David Sackstein

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...
תגים:, , , ,

A Custom Animation Class - Point3DAnimationUsingPath by David Sackstein

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...
תגים:, , ,

TreeView DataBinding and The Composite Pattern by David Sackstein

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...

WPF, Windows Forms and ATL Part 3 by David Sackstein

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...

WPF, Windows Forms and ATL Part 2 by David Sackstein

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...
תגים:, , , ,

WPF, Windows Forms and ATL Part 1 by David Sackstein

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 rest of this post I will describe...
תגים:, , , ,

ATL and Visual Studio 2010 Beta 1 by David Sackstein

I am working on a post or two on the subject of WPF Interop with ATL and Windows Forms. I would like to demonstrate: ATL Simple Control in a WPF Window ATL ActiveX in a WPF Window Windows Form user control in a WPF Window WPF control in a Windows Form However, I encountered an unexpected setback: Its very difficult to create ATL projects with Visual Studio 2010 Beta 1! The ATL Wizard doesnt add implementations in the control to methods you add to the interface. When implementing connection points...

Aggregate CheckBox for DataGridCheckBoxColumn (Part 3) by David Sackstein

I described the problem at hand in the first post in this series. In the previous post I described the high level design of the source code that demonstrates my solution. In this post, I will describe the EmployeeUserControl and summarize. You can download the complete source code for the article here . DataBinding Design First, let’s decide what should be bound to what. From the very start we made the fairly obvious decision to use an ObservableCollection<Employee> as out ItemsSource. Combined...
תגים:, ,

Aggregate CheckBox for DataGridCheckBoxColumn (Part 2) by David Sackstein

In the previous post I described the requirement to create an aggregate CheckBox for a DataGridCheckBoxColumn. You can download the source code for my solution here . In this post I describe the high level design of my solution as documentation for the source code. If you are looking for the WPF techniques themselves, you can skip to the next post ( Part 3 ). Setting the Scene The project contains three assemblies: PresentationLayer: This is a WPF window application. UserControls: A class library...
תגים:, ,

Flabbergasted! by David Sackstein

I am currently working on a UI project for a customer. The natural choice was WPF – but I’ll get back to that later. I encountered some interesting problems and starting to prepare some posts with the solutions I found. They not quite ready yet so I delayed posting them for a few more days. And then … then … I found Mole 4.2 - and I was flabbergasted! This you have just got to see. Mole is an extremely powerful Visual Studio visualizer. Visualizers allow you to drill down into objects (and sometimes...
תגים:,
Powered by Community Server (Commercial Edition), by Telligent Systems