Debug WPF Design Time Errors

In one of my posts I told about WPF Visual Designer and how to display design time data in MVVM projects. I hope you had a chance to try it and work with this nice WPF feature because it is one of the most time-saving features in WPF development. If you still didn’t – I suggest you start using it immediately.

But like in other cases, when writing a code you can make an error where you initialize your design time data. When it happens you won’t be able to see you design time data and it can be very difficult to find where the problem is, because you can’t debug design data in a regular way. In this post we’ll talk about how to debug design time data.

Read more

To finalize, or not to finalize, that is the question

Remember that pre dot net world, when you were the one responsible for allocating memory for the program you wrote and even worse – you needed to free memory trying to prevent memory leaks? It wasn’t so nice, to say the least.

Then, one day, Microsoft presented the .NET (there was also Java on the way) and suddenly life became much easier. There was no need to deal with allocating and freeing memory because of the Garbage Collector, which did all the dirty work for you and life became “pink” and easier.

However, not everything was “pink”. When using the unmanaged resources on your application, you still have to free them, otherwise you have a problem. This post is all about showing you how to do it right. Read more

How to handle Dependency Property changes

In my work I needed to handle Dependency Property changes and to perform some operations when it happens. In my case I use ScrollViewer and when ViewportWidth or ViewportHeight was modified, I required to peform some layout operations. ScrollViewer does not define any event that I can use in order to handle properties’ changes.

DependencyPropertyDescriptor  class helps us to solve our problem. First of all we need to create DependencyPropertyDescriptor:

After it we’ll call AddValueChanged method. First argument of the method is source element and second –function, that will handle property modification:

That’s all. Bellow you have full source code for the post.

 

Hope it was usefull for you.

Use WPF Visual Designer with ViewModels

The problem

I would like to talk about problem many WPF developers are familiar with. Especially those who work with MVVM. When I design screens received from a designer and want to see the result of the change I’ve recently made, I have to compile the solution and run it. And if there is another change, I have to perform the same process all over again. If I could find a solution, it would save me a lot of time.

Read more

WPF Binding Exception

When I began working as a software developer (during my first years as a program developer), I worked on a project which included a redesign of an application based on WinForms. A talented designer worked with me and did a great job, but then I had to implement her beautiful designs into WinForms, which was not such a great experience (anyone who worked with WinForms will understand me). Some things went great, but some others were too difficult. I needed to draw controls and use win32 in order to apply designs that were not supported by WinForms.

Then I discovered WPF. The first time I heard about it was at Microsoft presentation and I was amazed by the variety of useful things this technology provides and how easier my life could be if I would have used WPF instead of WinForms. Eventually, I continued developing on WinForms, but my following developments were done on WPF and it was a real pleasure! Read more