One collection – many views

Let’s imagine we have a huge collection of some objects (may be our data objects) and we need to filter this collection and display only a part of its elements in different places in our WPF application. Instead of creating many different instances of sub collection we can use the benefits of collection views. CollectionView is a wrapper around a collection that allows filterin…

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

TabControl and selected tab index

It was obvious for me that a TabControl in WPF, which is a container for TabItems, has a dependency property indicating the index of current tab. I was, also obviously, not surprised when I found TabIndex property on the TabControl. So without unnecessary thinking and spending time on that, I have set a binding to this property in my application. I was hoping that by changing b…

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

Plugins in WPF MvvM with MEF

In this post I will show you the way we can implement a plugin functionality in WPF MvvM application with use of Managed Extensibility Framework (MEF). MEF is a tool that may facilitates extending and decoupling your application. In some scenarios it is very similar to Dependency Injection, but is rather focused on one primary purpose: Import and Export of objects. What is good…

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

Cross-property validation in WPF MvvM

In a previous post I have described hot to utilize a INotifyDataErrorInfo interface. Today I will show you my solution for automated cross-property validation integrated with the ModelValidation base class from previous post. First I add a custom CrossValidationAttribute and later on a virtual method which will be called from above CrossValidationAttribute for each property mar…

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

Utilizing INotifyDataErrorInfo in WPF MvvM app

Today I will show you how I utilize the INotifyDataErrorInfo interface to accomplish validation mechanisms in WPF application.   A time ago I have described how to validate model in WPF application with use of IDataErrorInfo interface. Now in WPF 4.5 we have another possibility which is the INotifyDataErrorInfo interface. The MSDN documentation is here a little scarce, but…

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

WPF switch panel

The panel which switch its content depending on the value of boolean flag is the topic of this post. The WPF application I’ve recently coded was a MvvM application and had a number of editable fields. The fields were editable only in specific circumstances and when the proper flag IsEditionMode has been set to true on the ViewModel. For trivial cases I could use TextBox with Is…

By Mirek on (tags: custom controls, SwithPanel, WPF, categories: code)

Automatic ICommand activation in WPF

Today I will present you my solution for automatic command activation in WPF MvvM application. Standard command implementation that can be binded in XAML looks similar to this then you have to create the instance of the command and assign it. I usually use the DelegateCommand which is a ICommand implementation with Actions inside. Now since the first part is necessary, because …

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

Strange phenomenon after moving to Visual Studio 2012

Recently we moved our main WPF project to .net framework 4.5 and Visual Studio 2012. Then when I tried to preview some of basic views in Visual Studio designer I faced some strange problems. We have several user controls that we use in our views. The error we get was After deeper investigation we found another exception This was mysterious, because when running the application,…

By Mirek on (tags: .net 4.5, user control, Visual Studio 2012, WPF, categories: architecture)

Simple, bindable PieChart in WPF

Today I will show you a simple way to have a pie chart in your WPF application with use of ItemsControl. The pieces of the pie will be binded to the undergoing item model collection. Let’s take a look at it. The goal is to achieve a pie chart presented on the picture below, having just a collection of items.     Each item should be an object with following properties …

By Mirek on (tags: itemscontrol, Pie Chart, WPF, categories: code)

Simple validation in WPF MvvM Part 2

In a previous post I showed you how to use IDataErrorInfo interface to implement simple validation mechanism in WPF MvvM application. In this post we will try to extend and customize this approach a little. It would be nice I the fields of the form be validated on Save button click. So the user will not see error messages when he opens the for for the first time To achieve that…

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