background preloader


Facebook Twitter

Allowing CommandManager to query your ICommand objects. One of the great parts about commands in WPF is that they know if they can currently execute or not.

Allowing CommandManager to query your ICommand objects

When they cannot execute, the control(s) that are set to execute the command will be disabled automatically. For example, if your application has no changed data, the Save toolbar button will automatically be disabled, assuming its Command property is set to the Save command. WPF will automatically ask all of the commands being used in your UI if they can execute. This happens at various times, such as when input focus shifts to another control, an item is selected in a list, etc. You can also programmatically trigger this to happen by calling the CommandManager’s InvalidateRequerySuggested static method.

Here’s the hitch: this beautiful system of commands automatically notifying the UI that they cannot execute only works out-of-the-box for RoutedCommands. Fortunately there is an easy solution to this problem. Public void Execute(object parameter) { // Do something awesome. } } Refresh / Update WPF controls. Sometime in the past, a friend asked me how to update a control to show status while his code is doing a loop of stuff.

Refresh / Update WPF controls

Essentially changing the text of a label (or sophisticatedly we can say a text-based progress bar). In my past coding with MFC and WinForms, it's fairly easy enough, you just invalidate and do an update (Invalidate / UpdateWindow in MFC or Invalidate / Update in WinForms). This approach also coincides with how Windows UI operate, where you specify the region that needs to be redrawn and then you send a message to the message pump for that control to paint itself.

WPFDeveloperTools - Download: WPFDeveloperTools - First Public Release. Taking snapshots of WPF animation - Eric Gunnerson's Compendium. I've been playing around with WPF animation, and ended up wanting to take a snapshot of an animation at a specific place.

Taking snapshots of WPF animation - Eric Gunnerson's Compendium

Specifically, I have a canvas that has some pictures on it that are moving, and I want to be able to save a bitmap of what it looks like at a specific time. Getting the bitmap is pretty easy, using a RenderTargetBitmap and a VisualBrush. private BitmapSource CaptureScreen(Visual target){ Rect bounds = VisualTreeHelper.GetDescendantBounds(target); RenderTargetBitmap renderBitmap = new RenderTargetBitmap(800, 600, 96, 96, PixelFormats.Pbgra32); DrawingVisual dv = new DrawingVisual(); using (DrawingContext ctx = dv.RenderOpen()) { VisualBrush vb = new VisualBrush(target); ctx.DrawRectangle(vb, null, new Rect(new Point(), bounds.Size)); } renderBitmap.Render(dv); return renderBitmap;} That gives you the state of the objects pre-animation, but what I really wanted was the state of the objects during the animation.

Which should have worked fine, but didn't. Data Binding in WebControls. Download source - 3.37 Kb etc) --> Introduction Over the past few months I have been creating a variety of WebControls some of which have needed access to a DataSource such as a DataSet in order to work properly.

Data Binding in WebControls

Adding a DataSource to your WebControl is relatively easy however the tricky part is when you need to interact with that property in the Properties window e.g. in the same manner as you would for a DropDownList control etc. Now if you are lucky and you get the query right in MSDN you will come across the following article Implementing a Web Forms Data-Bound Control Designer. Visual Studio WPF Designer Forum. WPF LOB Feedback. Building a Perfect WPF Developer Workstation - Tim Sneath. Hosting a WPF Control in a Windows Forms Application - MHender Rambles On. Patterns & Practices: Composite WPF Contrib. WPF DataGrid Practical Examples. Download source code - 65.44 KB Contents Introduction A DataGrid is a user interface component for displaying tabular data to the user, typically providing sorting and editing functionality, among others.

WPF DataGrid Practical Examples

DataGrids have been the work-horse of various frameworks such as ASP.NET (GridView) and Windows Forms (DataGridView). However, DataGrids in WPF are rather conspicuous in their absence! ChartingStylingGuide.pdf (application/pdf Object) Styling Microsoft’s WPF datagrid - Jaime Rodriguez. Microsoft’s WPF datagrid has a lot of properties and styles you can tweak to get it looking right (if you are a designer).

Styling Microsoft’s WPF datagrid - Jaime Rodriguez

Below, find my cheat sheet to styling the grid. It is not 100% comprehensive but it gets you far and has a few very useful tips & gotchas. At the highest level in the DataGrid , you can change the look & feel by setting some of these: Here, you can see a visual representation for a few of these properties (the visual is not all inclusive); this will give you an idea of what this article will cover.

Backgrounds: The interesting part are the relationships amongst the backgrounds: Background – sets the whole data grid’s background. Here is an example of overriding RowStyle to tweak background based on AlternationIndex: Notice that, on purpose, I only override AlternationIndex = 2,3. Datagrid Column Headers I usually customize the header on a data grid to accomplish one of two tasks: Tweak the background of the headers, including triggers for hovers, selected, etc. A WPF Problem Solved Two Very Different Ways - Using XAML Only - Using a Custom Control.

Introduction This article is about developing a XAML only WPF CheckListBox and ListBox with Selection Indicator control styles, and taking the same requirements and building a custom control that takes a very different approach to the problem.

A WPF Problem Solved Two Very Different Ways - Using XAML Only - Using a Custom Control

This article is about taking a concept and running with it. It's about this developer's desire to recreate a complex control using only XAML markup. We will explore the XAML only approach, then toss everything into a blender, and pour out two WPF Custom Controls using VB.NET. This article and its controls were inspired by Josh Smith's awesome article, The WPF Thought Process. I read Josh's article several times, attempting to glean and learn as I do from all the WPF articles here on The Code Project. To get the most from this article, please read Josh's article before reading this one.

WPF Binding Cheat Sheet. WPF Binding Cheat Sheet « Method ~ of ~ Tried. Download. WPF Enum List Converter. Introduction This article demonstrates how to bind a C# enum definition to a WPF ComboBox, which is not as simple as it first seems.

WPF Enum List Converter

The solution was extracted from a real-world commercial application. Background Enum definitions are great for defining small fixed lists of options for a property. They are easy to define in code, and are strongly typed, so they help produce robust code. My data models tend to use a lot of enums to define class specific properties. I did not want to reference the combobox in the code-behind class, I wanted the bindings to be entirely defined on the XAML side.

Using the Code The solution to the enum problem is implemented in two small C# classes described below. The source code contains everything needed to build the example, including the test data, which is taken from the SQL Server AdventureWorks sample database. Drag & drop in WPF part2 ... - Jaime Rodriguez. Last part, we focused on the drag...

Drag & drop in WPF part2 ... - Jaime Rodriguez