Simple validation in WPF MvvM using IDataErrorInfo

In this post I will try to demonstrate the simplest validation approach for Windows Presentation Foundation application designed in Model View View-Model pattern. We will be using data binding and IDataErrorInfo implementation. Ok. Let’s assume we have simple data model ProductModel which looks like this So we have Name, Price and Amount text boxes, which we want to bind to the…

By Mirek on (tags: IDataErrorInfo, mvvm, validation, WPF, categories: code)

Parametrized BooleanToVisibilityConverter

Windows Presentation Foundation allows us to create our own value converters and use them in XAML bindings. WPF also comes with a set of predefined converters. One of them is BooleanToVisibilityConverter. It this post I will show you how to create own version of this converter with parameter feature supported. BoleanToVisibilityConverter sets the Visibility value to Visible whe…

By Mirek on (tags: BooleanToVisibilityConverter, IValueConverter, WPF, categories: code)

Gradient generator for WPF

Have you ever straggled with generating and polishing gradient for wpf in xaml? I did many times. Did you use any tool for that, except Visual Studio Property tab? I didn’t. Until I stumble upon Online Gradient Maker. I thought the Visual Studio designer and editor is all you need to create rich WPF apps, until I had to create a style for radio button with circular gradient on …

By Mirek on (tags: gradient, WPF, XAML, categories: tools)

Custom WPF check box with inner shadow effect.

Today I will show you how to override the CheckBox control template to style it in custom way and add a sexy looking shadow effect. We want to replace the standard windows checkbox look with something cooler and fit to our application design Windows Presentation Foundation controls are based on Styles and templates. When you want to change the look of the control you have to st…

By Mirek on (tags: CheckBox, inner shadow, styling, WPF, categories: code)

WPF Caching visual elements for better performance

More precisely how can we cache UI elements, since the property I’m going to describe is located at UIElement class, to improve the performance of the WPF control. Recently I had to implement a custom control in WPF. The goal was to display a list of some processes with steps in a Gantt chart. I decided the control will be based on a set of Grid panels where each cell indicates…

By Mirek on (tags: BitmapCache, CacheMode, custom controls, Gantt, WPF, categories: architecture)

WPF MvvM - simple approach

Model View View-Model is one of most popular design pattern used in WPF applications. Thanks to binding, dependency properties and other features, WPF has been adjusted and, I believe,  somehow designed to be used with MvvM pattern easily. There are many MvvM frameworks for WPF which support creating loosely coupled and scalable wpf applications. We can use Prism, Cinch, M…

By Mirek on (tags: mvvm, WPF, categories: code)

XAML styles in external assembly

Today I will show you how to use the XAML styles located in resource dictionary in external assembly. I will also try to point out the common problems that can raise during this process. We start with one project WPF application and the resource dictionary included in main window dictionary. and we want to extract the styles from section Window.Resources, place them in separate…

By Mirek on (tags: resources, styles, WPF, XAML, categories: architecture)

Customizing WPF combo box style

It this post we will try to create a custom combo box style which adjust the look of standard control to our needs. In general we will try to change this standard look of combobox and achieve something like this Great styling examples for combo box, buttons and tab items can be found on Codeplex, which I based my work on. If you are not familiar with styling in wpf there is a l…

By Mirek on (tags: combobox, CustomTemplate, style, WPF, categories: code)

Localized enums with Entity Framework Code-First 4.1 in WPF MVVM and ASP.NET MVC 3. Part 3)

Part 3. Displaying and binding localized names of enum values in ASP.NET MVC 3 application To display localized enums in ASP.NET MVC 3 application we use custom description attribute described in Part 2) and extension method to get the description for each enum value. The type converter is not useful here so we need another approach to achieve the goal. Let’s generate the editi…

By Mirek on (tags: ASP.NET MVC, Code First, Entity Framework, enums, lozalization, mvvm, WPF, categories: code)

Localized enums with Entity Framework Code-First 4.1 in WPF MVVM and ASP.NET MVC 3. Part 2)

  Part 2. Displaying localized names of enum values in WPF application To achieve the human readable enums I have performed following steps. For each language I want to support I have added a resource (.resx) file with key equals the string representation of the enum value.   Then we decorate our enum values with Display attribute as follows As a description we can pr…

By Mirek on (tags: ASP.NET MVC, Code First, Entity Framework, enums, localization, mvvm, WPF, categories: code)