Using the AutoCompleteBox in the WPF Toolkit
In this blog post I will look into the AutoCompleteBox in the WPF Toolkit, added in the february release of the WPF Toolkit. The AutoCompleteBox works, just the way I had expected it, but it actually adds a couple of more features than what I would have expected. Only one dll is needed to use the AutoCompleteBox:
System.Windows.Controls.Input.Toolkit
I will not describe all the features in details, only describe the basics of what you need to know to use it! To add a basic AutoCompleteBox, I just add the following line to my XAML:
<Controls:AutoCompleteBox Name="autocompleteBox" />
Unit testing Caliburn applications in NUnit
This is part three in my series on Caliburn, if you haven't please read Part 1: Getting started with Caliburn and Part 2: Multiple Views on one ViewModel.
In this post I will look into the unit testing features of Caliburn and try to give a quick introduction to the essentials of what you need to know to write a couple of small unit tests in NUnit. The documentations on caliburn.codeplex.com on unit testing is fairly good, so I will only try to fill in some missing pieces and give a quick start guide to unit testing Caliburn. If or when you bump into problems with the simple setup described here, it's time to move over to more detailed documentation available in both the documentation and discussion forum on Codeplex.
Optional parameters in C# 4.0
A while back I blogged about the great features of the Dynamic Language Runtime introduced in .Net 4.0. Today I will look into another great feature introduced in C# 4.0, namely the new named and optional parameters.
If you are familiar with C++, you have probably used optional parameters earlier, but C# has missed this feature until now. As a work around we had to use overloaded methods, but in the concept of clean code, I'd rather prefer to use optional parameters!
Splash screen in WPF
Remember the time when adding a splash screen to application was a hassel? In WPF this is now extremely simply, follow these few steps, and you splash screen is available in your WPF application!
Running NUnit in an STA thread
While unit testing a WPF Caliburn application, I bumped into the following error:
The calling thread must be STA
and I ended up with a cross-thread exception. When diving into this problem I found that TestDriver.Net actually runs in STA (acronym for Singel Thread Apartment) by default, but NUnit is not! It is however a fairly simple configuration change to get NUnit running in STA. Add or update your app.config in your test project with following:
How to unit test private methods in C# using NUnit
Ever had the need to unit test a private method? Ever change a private method to public just to able to write a test for it? You are definitely not alone! A couple of weeks back I had a very interesting discussions with a very good colleague of mine: "What to do if I want to unit test a private method in C#". In this post I will show how you can use NUnit in combination with Reflection to unit test private methods!
The is keyword: Yet another hidden treasure of C#
A while back i blogged about the yield keyword and called it a hidden treasure of C# as I seldom see it used, and many senior developers never use it! Today, I came across a similar one, namely the is-keyword. And frankly, I had actually forgotten about myself, even though I have used it in the past on several occasions.
Dynamic Language Runtime in .Net 4.0
The upcoming .Net 4.0 contains many new and exciting features, in this blog post I will describe some of the new features of the DLR including the dynamic keyword.
To quote MSDN:
The dynamic language runtime (DLR) is a runtime environment that adds a set of services for dynamic languages to the common language runtime (CLR). The DLR makes it easier to develop dynamic languages to run on the .NET Framework and to add dynamic features to statically typed languages.
The architecture of the DLR in combination with the Common Language Runtime CLR and C#, IronPython, IronRuby and Visual Basic is visualized through this illustration:
As seen from the illustration, the DLR adds three new and important features to the CLR:
Why use Custom Control instead of User Control in WPF?
When I first started experimenting with WPF I was quite confused with the new custom control introduced in WPF. I did a quick Google search but never got the full understanding of the difference, but I read somewhere that in most cases a custom control was not necessary, so I just focused on the regular user control back then.
Getting started with Caliburn Part 2: Multiple Views on one ViewModel
The documentation and tutorials on Caliburn is still very limited, and is one of the biggest obstacles getting started with Caliburn right now. In this post I hope to fill some of the gaps I have seen in the lack of documentation by showing how you can easily hook up two Views to one ViewModel.
A quick start guide to yield return and yield break
The yield statement was introduced in .Net 2.0, but I am a bit surprised that I meet many senior developers who has never used yield return (and yield break)! For some strange reason, yield has become some kind of hidden treasure in .Net. Through this post, I hope I can show some simple examples, and give some of the ideas, benefits and limitations with yield.
Working with globalization, string parsing and number formats in C#
On a project I attended a couple of years ago, we struggled a lot with string parsing, date formats and cultures. The product was shipped to among others China, Japan and US, and getting your code to work seamless in all culture formats can be a bit of a hassle if you are not fully familiar with how .Net and C# handles cultures and globalization. Back then I crated a small Windows Forms application to help me fully understand the details of conversions and parsing to avoid problems when our application was run on e.g. a Chinese laptop.
Memoization using generics – Part 2
This is Part 2 of my series on Memoization. In Part 1 I described the basic principles behind memoization, and showed some examples on how to create an effective generic method to do memoization of methods with zero and one parameter. In this post I will show how to do memoization of methods with two parameters
Getting started with Caliburn
The lack of documentation and examples of usage is one of the biggest obstacles getting started with Caliburn. I hope this article can help somewhat!
One of my biggest fears when starting a new project is heading in the wrong direction and not realizing that we are headed for disaster until it's too late. Due to architectural decisions, this is always a worry, but the new project is based on WPF, the risk and possibility of a failure is drastically increased. I'm afraid that my WPF projects become "Windows Formish", not taking advantage of MVP/ MVVM.
This is Part 1 of my series on Caliburn, Part 2 on multiple views on one ViewModel can be found here, and Part 3 on unit testing Caliburn can be found here.
Caliburn was designed to aid in the development of WPF and Silverlight applications, enabling easier use of among other MVP and MVVM. This article will be a walkthrough of a rather simple WPF application based on Caliburn. The example used here is a very simple application retrieving a value from a textbox, publishing it to an EventAggregator, and then let another component handle the published message. Hopefully I am able to show some of the advantages of Caliburn through this example.
Closing in on 20 000 reader on my article at CodeProject!!!
Back in 2006 when I started working with .Net, I posted an article at The Code Project, where I wrote about Sending parameters at thread startup. My competence with .Net has grown rapidly since then, but I check back today to check my profile at The Code Project, and realized that my article was read 20 000 times!
Adding C# and ASP.Net to Blogger (Part 2)
In one of my earlier posts I recommended using Windows Live Writer and the "Paste from Visual Studio" plugin to add code to your blog. But two days of struggling with layout I gave up, and stumbled upon the C# code formatter which is very easy to use!
Memoization using generics and lambda expressions
Memoization is a hidden treasure of programming techniques. Most developers has a good understanding of caching and use it to optimize queries, but why even do calculations on cached or live data, when you don’t need to calculate at all?
Adding C# and ASP.Net code to Wordpress
In the case of WordPress, adding C#, ASP.Net and similar code is very simple. Just use the sourcode tag in the following way (discard the underscores):
Adding C# and ASP.Net code to Blogger
Many developers ask, how can I paste C# code in my blog? I have looked into several ways of doing this, my verdict: Use Windows Live Writer!
Logging in .Net: a short study
I have been using different third-party logging tools for both .Net (C# and C++) and Java, but in my current project we are using a custom logging tool. Don't ask me why we have written our own framework for this, but I guess it's partly because we have worked on our current code base since before .Net 1.0 was released, hence I guess the number of available frameworks at that time was quite limited. But now I am tired of spending time and money maintaining code we could get for free elsewhere!
Using icons in windows applications
Today I came across the same problem that I have had many times earlier: I need a new icons in an application, this time for a refresh button. So what do I do? I Google it ofcourse and get hundreds of hits to all kind of crappy icon libraries, most of the costing me a fortune!
.png)
