Display HwndHost Inside ToolTip/ContextMenu This post is a further elaboration to my reply to this MSDN WPF forum thread. Before digging into the details of how to solve this issue, let's start with some background information on ToolTip/ContextMenu and HwndHost. In WPF, ToolTip/ContextMenu is hosted inside a Popup, Popup is essentially a hwnd with WS_POPUP window style. By default, the Popup created by ToolTip and ContextMenu services will have AllowsTransparency property set to true to enable layered windows on it. The caveat here is that the implementation of ToolTip and ContextMenu has hardcoded the AllowsTransparency property value when creating Popup, and it seems that this will not change at least in the next version of WPF. Here is the complete implementation of PopupBehavior: using System; using System.Security; using System.ComponentModel; using System.Windows; using System.Windows.Media; using System.Windows.Threading; using System.Windows.Controls; using System.Windows.Controls.Primitives; Popup popup = null;
(WPFS) MVVM Light Toolkit: Soup To Nuts Part I While I’m not a zealot on the topic, I do believe that MVVM offers one of the best patterns for Windows Phone development and so, moving forward, the Windows Phone From Scratch series will incorporate MVVM in general, and the MVVM Light Toolkit in particular. I’m more than convinced that MVVM is an essential pattern for Windows Phone Development; and while there are many excellent frameworks to make MVVM development easier, the one I personally prefer to work with is the MVVM Light Toolkit and so it is the one I’ll focus on. I make the case for MVVM in this article, and so I won’t rehash that material here. I will not assume any background with MVVM or with the Toolkit beyond those two links. In that spirit, let’s begin by creating a two page MVVM application. Creating the Application To begin, open Visual Studio and click on New Project. Select MvvmLight and name the project MvvmLightNavigationBehaviorAndMessages. Linking the View and Its View-Model ViewModelLocator Adding A Second Page
Developer Review - Four ASP.NET MVC View Engines - Coding4Fun - Site Home - MSDN Blogs In this Developer Review, we evaluate four view engines available for use with ASP.NET MVC. First, we discuss the role a view engine plays in a website built with ASP.NET MVC, then we provide details about the four view engines in order to help you decide which one suits your needs. When we refer to a view engine in ASP.NET MVC, we are talking about three pieces of functionality: · A template locator/provider (implementation of IViewEngine) · A template that can render itself (implementation of IView) · A template engine that can parse and compile the view file syntax into executable code Combining these three pieces, a view engine provides your controllers with the ability to translate views into Html. Though the view engine that ships with ASP.NET MVC has all the functionality you need to create views for just about any website project, it is also easily replaced. As with choosing a programming language in .Net, there are many reasons why you may choose one view engine over another: Loops 1.
A Practical Quick-start Tutorial on MVVM in WPF Download source - 15.6 KB Introduction This article gives a practical quick-start tutorial on MVVM pattern in WPF for application developers. Background The MVVM (Model-View-ViewModel) Design Pattern is a Design Pattern introduced recently in the software development community. According to Wikipedia, the MVVM pattern can be described as follows: Model: As in the classic MVC pattern, the Model refers to either: an object model that represents the real state content (an object-oriented approach), or the data access layer that represents the content (a data-centric approach). You can find many tutorials on developing MVVM WPF and Silverlight applications on the web. This article assumes that readers can create some basic WPF applications, create "XAML" files, and understand the basics of "bindings". Let us start this tutorial by first setting up the development environment. Set up the development environment Create a WPF MVVM application Add a model class Student StudentsModel Run the application
ListView Layout Manager Download v1.3.0 - 22.9 KB Introduction Using a ListViewLayoutManager allows controlling the behavior of the column layout of ListView/GridView controls: Fixed Column: Column with fixed column width Range Column: Column with minimal and/or maximal column width Proportional Column: Column with proportional column width The Range Column allows to restrict the column width as well as to fill the remaining visible area with the column. As known from HTML tables or the Grid control, the Proportional Column determines the column widths on a percentage basis. Visibility of the vertical ListView scrollbars Changes of the ListView control width Changes of the width of a non-proportional column The implementation supports both controlling through XAML or Code Behind. The class ConverterGridColumn offers object specific binding by using the interface IValueConverter. In the article User Settings Applied, I describe how you can persist order and size of the ListView columns. Fixed Column Range Column
Windows Phone From Scratch #17: MVVM Light Toolkit Soup To Nuts Part 2 This is the second part of the MVVM Light Toollkit Soup To Nuts (part 1 is here) within the Windows Phone From Scratch Mini-tutorial series. Today we look at an introduction to behaviors as a tool for migrating event handling from code-behind to the View-Model. Behaviors were originally introduced in Blend to empower designers, but they turn out to be enormously helpful to C# programmers as well. For example, it is a design goal to move as much of the (testable) logic of the program out of code-behind (where testing is more difficult) and into the View-Model. But what to do about events, such as the click event on a button? What We’ll Build To illustrate this, we’ll return to the example we began in part 1, and extend it by adding a button to MainPage that will cause the application to navigate to page 2. First we’ll substitute a behavior for the event handler Second we’ll use messages (in part 3) to tell the page to navigate to the new page Make the following changes to MainPage.xaml
Web Designers vs. Web Developers (Infographic) By Wix Let’s be honest. Being a web developer or a web designer doesn’t exactly give you an edge with the pretty girls (or guys) at your local pickup bar. If you were a part-time firefighter or investment banker, maybe. Here is an infographic of the differences between web designers and web developers. Click to enlarge.
Cinch MVVM Framework Code Generator Cinch source code: Download Cinch demo application which includes everything (including the Cinch code generator) Contents Introduction What is this article all about? Well, some of you may already know, while others may not, that I just finished writing a series of articles about my own MVVM framework for WPF called Cinch. There are six articles in the Cinch article series, and the source code for Cinch is now hosted at CodePlex. Here are the original Cinch articles in case you missed them, and want a read through: You may be wondering what is left to cover. Here is a screenshot of the Cinch code generator in action: And here is what the text highlighting looks like, which uses the most excellent AvalonEdit control by Daniel Granwald, which is a free control available from Daniel's AvalonEdit control allows custom syntax highlighting via the use of an embedded resource file called "CustomHighlighting.xshd", which looks like this:
Attached Behaviors vs Attached Properties vs Blend Behaviors Brian Lagunas asked a very good question based on seeing my sample video from my Pluralsight Windows 8 MVVM XAML Apps course, the gist of which was (paraphrased): “Why do you call them Attached Behaviors – won’t that cause confusion with what is an Attached Property and with Blend Behaviors?” My initial answer was along the lines of “because that is what we called them back in the day, long before Blend picked up the concept and created their own behaviors.” But Brian rightly pointed out that not everyone has as deep of history working with XAML as I do and a lot of people only associated the term behavior with Blend Behaviors. He also asked how to discriminate a simple attached property from an attached behavior. Here is my response: A similar discussion also recently came up while working with the Microsoft patterns & practices Kona team on Line-Of-Business guidance for Windows 8. Attached and Blend Behaviors Attached Behaviors
Windows Phone From Scratch #18 – MVVM Light Toolkit Soup To Nuts 3 This is the third part of the MVVM Light Toollkit Soup To Nuts (part 1 is here) within the Windows Phone From Scratch Mini-tutorial series. Today we look at an introduction to messaging as a tool for communicating, e.g., from the view-model to the view. What We’ll Build To illustrate this, we’ll return to the example we began in part 1, and extended in part 2 (you can download the part 2 source code here). We stubbed out the handling of that command, but now it is time to complete the logic, by having the view model cause a navigation from MainPage to Page 2. There is and should be no visibility of a view from a view-model, however, and so we need a mechanism for sending out a message in a bottle to be picked up by anyone who is interested. Messaging Fortunately, the MVVM Light Toolkit provides extensive support for messaging. Begin by creating a new class in the project in Visual Studio, and call the new class GoToPageMessage. You’ll need to include the supporting library,
Explaining to your boss (or your wife:)) why tier based architecture doesn't scale Two weeks ago I had the pleasure of presenting at the NY JavaSIG. The event was hosted by an old friend, Frank Greco, who has been doing a really great work keeping the NY Java community up to date with the latest and greatest for quite some time (Great work Frank !). Even though it was one of those freezing NY evenings, the room was packed with around 300 people. In this presentation, I used an analogy that I refer to in many of my recent talks to explain the fundamental limitations of the tier-based approach. I thought it is worth documenting this analogy, for those of you who are looking for a simple argument to convince their managers to open their mind to alternative approaches. It goes like this: Imagine a Coca-Cola production line that consist of three factory lines: one producing the bottles, one filling them and the third shipping them. Coca-Cola Factory - "Tier Based" You are probably asking by now how all this is relate to computing? Is there a better way ? Final words:
Styles Introduction Imagine you want to create an application with a unique design. All your buttons should have an orange background and an italic font. Doing this the conventional way means that you have to set the Background and the FontStyle property on every single button. <StackPanel Orientation="Horizontal" VerticalAlignment="Top"><Button Background="Orange" FontStyle="Italic" Padding="8,4" Margin="4">Styles</Button><Button Background="Orange" FontStyle="Italic" Padding="8,4" Margin="4">are</Button><Button Background="Orange" FontStyle="Italic" Padding="8,4" Margin="4">cool</Button></StackPanel> This code is neither maintainable nor short and clear. The concept of styles let you remove all properties values from the individual user interface elements and combine them into a style. To make the style accessible to your controls you need to add it to the resources. To apply the style to a control we set the Style property to our style. What we have achieved now is Style inheritance
Dialogs the MVVM Way Download source - 44.9 KB Introduction The Model-View-ViewModel pattern is really nice since it clearly defines the responsibility of the View, the ViewModel and the Model. There should be no direct contact between the View and the ViewModel and via the databinding mechanism, this is easily possible. However, I ran into a problem when a confirmation was required from the user before removing an entity chosen by the user. In my quest to find a reasonable solution on the web, I ran into the following solutions: Just show the messagebox from the ViewModel. Solution 1 & 2 where directly discarded, solution 3 was getting close however I found it quite limiting to react to a change to a message. Because I was unable to find a solution matching my requirements, I came up with the solution mentioned in this article. The Solution This resulted in the following design: Using the Code InteractionBehaviorCollection InteractionBehaviorBase MessageBoxInteractionBehavior The View, MainWindow.xaml ViewModelBase
Windows Phone From Scratch #19 – MVVM Light Toolkit Soup To Nuts #4 Let’s back up a bit and examine the day to day use of a View Model, and binding to the view model. In this mini-tutorial I’ll show the basics of binding a collection that sits in a View Model to a list box in the view. Let’s create a simple application that will display the full name of customers and their email, and that will (eventually) allow the user to click on one and go to the details about that customer. We start by creating a new MVVM application for Windows Phone. Creating the CustomerCollection The CustomerCollection class exists to give us some data to work with. Binding the ItemSource The key to understanding how MVVM handles the data binding is that the DataContext for the View is the View Model. When you set up the MVVM Light application the data context for this page was set to the view model, and there you’ll need a (read only) property for binding. Thus, back in Visual Studio, in the code behind file, MainViewModel.cs, enter the letters mvvminpc and press tab.