WPF

WPF
Microsoft's MVP program and Rob Eisenberg

This is a long read, but it's got some detailed insight on the MVP program at Microsoft. I've heard these sentiments before, and I'm sure that it's not black and white. Regardless, Microsoft's actions in this case are unacceptable. http://devlicio.us/blogs/rob_eisenberg/archive/2012/01/04/how-i-lost-regained-and-then-turned-down-an-mvp-award.aspx If you don't know Rob Eisenberg, he's the creator of Caliburn and Caliburn Micro frameworks for XAML based platforms (WPF, Silverlight, WP7). If you want to have your mind blown, take a look at his source code for Caliburn Micro (and even more so for Caliburn). While you're at it, watch his "Build your own MVVM framework" presentation....

posted @ Thursday, January 05, 2012 2:34 PM | Feedback (0)

WPF Focus - Different on Win XP than Win 7

Focus issues are notoriously challenging. I just ran into a case where it even acts differently on Win XP vs. Win 7. I have an textbox that I re-templated to use the Auto Complete from the WPF Toolkit. The goal was to turn a normal textbox into an autocomplete by simply setting a style. So, in this case, I override the TextBox control template and embed an autocomplete inside of it. … But now when I tab through the controls, it stops once for the parent textbox and then again for the contained autocomplete inside. Fix #1...

posted @ Thursday, October 27, 2011 4:37 PM | Feedback (0)

Making Sense of WinRT - Part 1 - I like it, BUT...

Build 2011 was amazing! It answered some lingering questions (XAML's future, Tablets, etc). It also presented us with some very impressive and fresh work that should ensure a bright future for Microsoft and the MS ecosystem. In a Post-Build time-frame, I'm looking back a bit and reflecting on what this all means. A couple thoughts come to mind... C++ Renaissance - Not a coincidence... The backing from MS for the "C++ Renaissance" and the "Going Native" movement are making a lot more sense. Initially, I kinda felt like these were unrelated to announcements that might be coming at Build. But looking back,...

posted @ Thursday, October 27, 2011 12:00 AM | Feedback (0)

Dependency Properties - Don't use Reference Types for Defaults

I thought I was going crazy! Data from one class was magically appearing in another instance. After double checking all code paths and walking through in a debugger, I found the cause… This is a user control, with a dependency property. The DP is a collection. Notice line 33 in the sample below. I am setting the "default value" for the property to an instance of a collection. BAD, BAD, BAD. It all makes sense now, given that a DP definition is static. It caught me off guard though because I'm used to setting the default...

posted @ Thursday, September 08, 2011 4:50 PM | Feedback (3)

MUF Runs on Windows Phone 7 and Silverlight 4

I am happy to report that the Monitored Undo Framework (MUF) now supports Silverlight 4 and Windows Phone 7! Today I did some maintenance on the framework in preparation for publishing it to NuGet. As part of the maintenance, I added binaries that target additional frameworks, including new support for: Windows Phone 7 Silverlight 4.0 .NET 3.5 It was pretty fun to see the same library working across all these platforms! Windows Phone 7… Silverlight 4 WPF (.NET 4.0)...

posted @ Saturday, June 18, 2011 11:58 PM | Feedback (11)

Monitored Undo Published to NuGet

In the words of James Brown…. I feel good! Why? Because today, I updated Monitored Undo Framework (MUF) and published it to the NuGet feed! Now I feel legit and official. I really like NuGet for a number of reasons… Convenience, time savings, and more. But one of the best things about it is just browsing the catalog! I found some really cool stuff in there that I wouldn't have otherwise stumbled on. Sure, one can Google with Bing or search codeplex or GitHub, or whatever. But if you find something in NuGet, it sort of...

posted @ Saturday, June 18, 2011 11:55 PM | Feedback (1)

Twisten 1.0 - Listen to Twitter

What is Twisten? Twisten is a twitter client that lets you listen to your twitter feed via Text-to-Speech using the built-in speech features of Windows. Why use It? Listen to twitter in the "background" while you do other stuff! The benefit of listening in the background is that you don't have to completely shift your focus away from your work to consume the tweets. Less context switching means you can stay productive, but still switch focus if you hear something that catches your attention. Download and Installation Getting Twisten is easy! It's a "Click Once" application,...

posted @ Tuesday, April 12, 2011 12:00 AM | Feedback (7)

WPF - Grid SharedSizeScope Doesn't Honor MaxWidths

I'm always hesitant to call something a bug because often it turns out to be my own misunderstanding. So I won't call this a bug yet, but I'm close… I sometimes use Grids inside of DataTemplate for an ItemsControl or a ListBox as a means to get a "column" effect for the elements. In this case, I set the parent with a Grid.IsSharedSizeScope="True" and then set the SharedSizeGroup on the ColumnDefinitions in the DataTemplate. Maybe there is a better way, but this works well for many cases. Recently, I ran into a case where I wanted the contents...

posted @ Wednesday, March 16, 2011 8:00 AM | Feedback (3)

WPF ImageBrush Will Not Properly Tile PNGs

Today I fought with the WPF ImageBrush and PNGs. I lost. For the life of me, I cannot figure out how to get a WPF ImageBrush to use a PNG and tile it appropriately. I tried various ViewPort and ViewBox settings, but it would not place the images directly next to each other. Instead, it had space between the images in the tiled output. I found Hanselman's article about the issues in WPF where the PNG does not use a 96DPI resolution. Even after getting these set to 96DPI, the things still wouldn't tile correctly. In my...

posted @ Monday, February 21, 2011 4:41 PM | Feedback (2)

WPF & Entity Framework 4 - Tales from the Trenches

I recently presented "WPF & RF4 - Tales from the Trenches" at the Cleveland .NET SIG. This presentation reviews tips, tricks, and lessons learned from building real world apps with Windows Presentation Foundation 4.0 and Entity Framework 4.0. Whether you’re doing desktop, Silverlight, or web development, the EF T4 template tweaks, MVVM usage, Undo/Redo implementation, and Reactive programming tips reviewed in this presentation should come in handy. The Photo Tagger sample application includes implementations of these topics and issues. I'd highly recommend pulling this down and taking a look. Downloads WPF...

posted @ Wednesday, October 13, 2010 7:00 AM | Feedback (6)

MUF is Live on CodePlex! (Monitored Undo Framework)

The Monitored Undo Framework (MUF) is now available on CodePlex! First of all, I'd like to offer a a big thanks to my client, who allowed me to make this available. MUF is a library for implementing Undo / Redo. It was written in tandem with a WPF application, but should work ok in Silverlight too. The "Monitored" part of the name refers to the way it builds the undo / redo stacks. It does so by monitoring the property changes in the model (or view model, or whatever) and adding a change item into the...

posted @ Wednesday, October 06, 2010 10:58 PM | Feedback (4)

.NET SIG: "Bag O' Tricks - WPF and Entity Framework" (Oct 12th)

Just wanted to plug my upcoming presentation at the Cleveland .NET SIG…. Oct 12th at the Microsoft offices in Independence, OH. Topic will be "Bag O' Tricks: WPF and Entity Framework" I plan to share lessons, tips, and tricks from my experiences with WPF 4.0 and Entity Framework 4.0. Even if you aren't using WPF, I think you may find these topics useful since many are are also applicable for other technology stacks, including Silverlight, Windows Phone, Windows Forms, and even web apps. EF Self Tracking Entities ...

posted @ Friday, October 01, 2010 10:41 AM | Feedback (0)

Be careful about with e.Handled in mouse or keyboard events

Today, I finally resolved an issue that I thought was related to WPF’s focus implementation. For some reason, I couldn’t get certain elements to get focus when I clicked on them. This was messing up a number of other things, including keyboard interactions and routed commands. I thought that I had some strange scenario that was preventing focus from going to my canvas. Maybe some issue with FocusScopes? Maybe the control wasn’t Focusable? It turns out that I had a number of event handlers set up for clicking, dragging, etc. In these, I was setting e.handled = true. Not...

posted @ Thursday, June 10, 2010 3:54 PM | Feedback (0)

WPF Routed Commands + MVVM

A lot of the MVVM guidance around commands suggest using a generic ICommand implementation, such as the RelayCommand or GenericCommand implementations. These are great for UI pieces that are bound directly to an underlying ViewModel and I use them frequently. There are still cases where a RoutedUICommand is exactly what one needs. Take, for instance, toolbar buttons or menu items that need to act on pages that are loaded in a WPF frame. In this case, a RoutedUICommand is appropriate since it is decoupled from the page, which may or may not be loaded at the time. ...

posted @ Thursday, June 10, 2010 3:44 PM | Feedback (0)

WPF Style and Template Resources – Order Matters

When working with WPF resources, remember to declare the resources in the correct order. A style or template that is referenced elsewhere must be defined before it can be used. In other words, if Style1 uses BrushA as a StaticResource, then BrushA must be defined before Style1. Otherwise, you’ll get fun errors like: Unable to cast object of type 'MS.Internal.NamedObject' to type 'System.Windows.FrameworkTemplate' It may be common knowledge, but it can be a real pain to diagnose. This is especially true if you have a large set of template and styles for...

posted @ Friday, May 07, 2010 4:44 PM | Feedback (5)

MVVM ViewModel Locator via WPF Converters

Laurent Bugnion’s work on MVVM Light introduced me to the ViewModel Locator pattern. The concept and implementation are really slick! From my perspective, ViewModel Locators do the following: Provide a simple, declarative way to connect a View to a ViewModel (duh). Enable design-time support, including the ability to connect an alternate data source behind the VM (cool!). I want a solution that lets me: Connect my XAML views to their associated ViewModels Handle a somewhat complex model with a hierarchy of domain model entities and...

posted @ Thursday, May 06, 2010 12:05 AM | Feedback (3)

Cancelling Selection Change in a Bound WPF Combo Box

Scenario A user selects a new value from a WPF combo box. You ask if they are sure they want to do this. User says “No”. WPF app is built with MVVM such that the combo box’s SelectedItem is bound to a property on the ViewModel. In the setter, you prompt the user and attempt to cancel the selection by discarding the new selected value. Here’s the UI XAML <Window x:Class="WpfComboBoxCancelSelect.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Cancellable...

posted @ Sunday, April 25, 2010 4:38 PM | Feedback (17)

Making WPF Remember Window Size, State, and Position…

I had a need to make my WPF app remember it’s size, position and state for the main window. A bit of “Binging” and I eventually heard the sound of found. Turns out there are a couple ideas out there, but the WINDOWPLACEMENT solution from MSDN seemed to fit the bill the best. This solution requires using some WIN32 API calls to get and set the information. The upside is that it seems to leverage the smarts built in to Windows regarding multi-monitor detection. The sample says that if the app was previously displayed on a secondary monitor that...

posted @ Thursday, March 04, 2010 11:15 AM | Feedback (1)

Should the Domain Model implement INotifyPropertyChanged?

I’ve been discussing an architectural question with a colleague this week. The scenario includes a WPF application, Domain Driven Design and MVVM. The goal is a relatively “pure” domain model where the classes in the model do not depend on any UI specific or other external assemblies. They are pretty much pure “POCO” objects. The question is whether it’s reasonable to have the domain model implement INotifyPropertyChanged and INotifyCollectionChanged (via ObservableCollection). INotifyPropertyChanged is defined in System.dll. It’s part of System.ComponentModel namespace. INotifyCollectionChanged and ObservableCollection are both in WindowsBase.dll. These are in System.Collections.Specialized and System.Collections.ObjectModel respectively. My take… go for...

posted @ Friday, February 26, 2010 12:20 AM | Feedback (4)

Skinning WPF – Call InitializeComponent in App.Xaml

For the past two days, I’ve been trying to get the infrastructure in place for skinning a WPF application. My goal is to support multiple skins and swap them out dynamically while the app is open. I could get the skin to affect the UI if I set it in the main window’s resource dictionary. However there was a quirk… The application uses WPF frames and pages. The skin was not showing up on frame’s pages. It would only show up on the main window. I searched Bing, Google and StackOverflow for answers. No luck. I...

posted @ Thursday, February 25, 2010 10:48 PM | Feedback (0)

MVVM: To Wrap or Not to Wrap? BLINQ and CLINQ to the Rescue! (Part 3)

In part 1, I asked the question “Do I expose the model directly, or do I wrap each item in its own view model?” We looked at two plausible options for handling this and saw some code examples of each. In part 2, I asked the question “Do I expose the model’s collections directly, or do I wrap each collection?” We saw the progression of code to implement this "brute-force". Then we quickly ran away screaming. This installment (part 3) asks "How do I cleanly and easily wrap the model’s collections with collections of ViewModels?" We'll take a...

posted @ Tuesday, February 09, 2010 10:45 PM | Feedback (8)

MVVM: To Wrap or Not to Wrap? Should ViewModels wrap collections too? (Part 2)

In my previous post, I asked the question “Do I expose the model directly, or do I wrap each item in its own view model?” We looked at two plausible options for handling this and saw some code examples of each. Now it’s time for a more interesting and challenging scenario: Do I expose the model’s collections directly, or do I wrap each collection? Let me paint this picture a bit so that we can see the scenario and the challenges. MVVM says that a ViewModel sits between the View (XAML) and the Model. The ViewModel (VM) exposes data from the model...

posted @ Tuesday, February 09, 2010 2:48 PM | Feedback (6)

MVVM: To Wrap or Not to Wrap? How much should the ViewModel wrap the Model? (Part 1)

The WPF community seems pretty happy with the MVVM pattern for WPF development. I can see why. It’s a great fit for WPF and its strong data-binding support. It provides a very nice layer for managing UI state, translating, formatting, and aggregating data. So let’s say that I adopt MVVM for my project. I think there are some scenarios that still need definition. One of these is “To Wrap or Not to Wrap?” Let me explain… MVVM says that a ViewModel sits between the View (XAML) and the Model. The ViewModel (VM) exposes data from the model plus additional view-specific details that...

posted @ Tuesday, February 09, 2010 11:11 AM | Feedback (12)

C# Snippets for Properties that support INotifyPropertyChanged

Since WPF likes INotifyPropertyChanged on bound objects, I looked for a snippet to help out. Matthias Shapiro had a good version for the interface implementation and a property declaration. I made a couple adjustments to the snippets based on personal preference (check if the value has changed before raising the event / remove the region from the property. Then added some property verification support based on the snippet sample from Philipp Sumi. The property verification uses reflection to check if the property exists. If not, it throws an exception. This function is marked with a Conditional attribute so that it...

posted @ Monday, February 01, 2010 3:08 PM | Feedback (9)