Archive for the ‘WPF’ Category

WPF Validation with Enterprise Library 5

Every application needs validation. However, in WPF it still costs too much effort to implement it. For instance, an ErrorProvider like in Winforms is not supported. There are several conditions my validation should satisfy: * I want to be able to specify validation in the data object. I consider this to be business logic and [...]

Timestamp and Rowversion columns

To check concurrency violations, it’s common to have a Timestamp column. This column represents some kind of version of that row, and has nothing to do with the actual time. In fact, the information is stored as binary(8) when non-nullable, and varbinary(8) when nullable. Anyway, the value in this column is being used to check [...]

Linebreak in a tooltip in xaml

Here’s a quick tip how to show linebreaks in a tooltip in xaml. I wanted to show properties on multiple lines (in a multibinding): ‘ This results in the following tooltip (where the mouse hovers on the text “FTP”):

Same width for items in ItemsControl

When you use an ItemsControl (or a derived class like the ListBox) to display items in a collection, most of the time, you want to use the same column width for all items. You can achieve this by hardcoding a width for the item in the datatemplate, but we all know this smells. There’s a [...]

WPF logging control

In almost every application you need/want some form of logging. I’ve made a sample solution that shows a usercontrol that visually displays the output. The text that is being logged is also written to a text file. Some main features: supports multithreading allows filtering on different trace levels possibility to show timestamp clear output Check [...]

Binding to Enums in WPF

A very common scenario: you want to bind an itemsSource like a comboBox to an enumeration. At first sight, this is harder to implement than you would imagine. When you google (or Bing) for solutions, you find a lot of examples that use a separate ObjectDataProvider that calls the GetValues() method on the specified enum [...]

Receive change notifications of a property of your dependency property

The title might be a bit cryptic, so I’ll explain it with an example. Scenario: You have a Customer which has an editable collection of Orders. You want to receive updates when an order changes. This is a common scenario, but I’ve noticed a lot of  wpf devvers still struggle with it. The trick is, [...]

Output the changed property in the databinding

A previous post of mine shows several options how to debug wpf bindings. Here’s another way to output the changed property (together with its new value). We’re using a custom PropertyChangedCallback that outputs some info. public static readonly DependencyProperty SomePropertyProperty =  DependencyProperty.Register(“SomeProperty”, typeof(string), typeof(Window1), new UIPropertyMetadata(BindingDebugger())); public static PropertyChangedCallback BindingDebugger() { // output the debugging info } [...]

WPF Feature suggestions

Microsoft is listening to the community more and more, and now offers us a site where you can suggest or vote on wpf feature requests! You get 10 votes… don’t waste them before you see all the ideas. It’s very informative to read them at least (incl the comments). … too bad it’s only possible to [...]

Invoking an ICommand

I wanted to reuse the logic of a Command defined in another usercontrol. The simple solution would be to create a separate, public method which I then could call from outside the control (and call this method in the Execute eventhandler). A more clean way is to directly invoke the Command! The ICommand interface supports [...]