Bindings, the glue that connects the view to the viewmodel part 1

If you have read anything I have written in the past, you are probably familiar with the fact that I am a huge fan of MVVM. There will have to be a lot of convincing before anyone gets me to switch pattern when working with Silverlight. There are several things one must learn and understand before one can use MVVM well.

There is the obvious part of learning the actual pattern and how it works. Learning how to build a good viewmodel, which is dependent on the data model and time and other circumstances. I know that there are a lot of people out there, especially bloggers, that will tell you that you have to build something according to this or that and be a true purist to be a good developer. However, a lot of these people forget that most of us do actually have clients that don’t feel like spending 2 months or $10.000 just to get it to be a perfect solution. In most cases one must adhere to this and make the best of the situation.

More...

Adding mouse wheel scrolling in Silverlight

I have just gone through a project that used mouse wheel scrolling of different elements in the application. There are probably a LOT of different ways of doing this, and this is absolutely not something new. But I wanted to make the solution re-usable by using attached properties.

The only issue with handling the scroll wheel is that Silverlight doesn’t support that, and does not expose an event for that. So you have to roll your own. This is not hard to do. All you have to do is handle the mouse wheel events from the browser using the JavaScript bridge.

On a side note, I did actually find this blog that talks about using UI Automation to handle the scrolling instead. Even though this seems like a cool solution, I was too far down the other line to turn back. So my solution is using the traditional JavaScript way…

More...

The MouseOver state visuals are reset by the Pressed even if I haven’t told it to

I’ve recently come up with a thing that is probably old news for most people. But to me it was new. I have styled a bunch of things lately, among them a bunch of buttons. Most of the buttons had MouserOver states, but no Pressed state. So I changed the template of the buttons and added my VisualStateManager (VSM from now on).

Being lazy as I am, I opened up generic.xaml and stole the original style for the button. And no, I did not use Blend! Why not? Probably because I’m a stubborn meticulous person who like coding things on my own…

More...

Changing the layout for the selected item in ListBox

I’m currently working on a Silverlight 2 application that will go on-line in about a week. It is not a big application, at least not if you look at the functionality in it, but it still has it’s challenges. Especially graphical ones. But this was one that I didn’t actually expect would cause a problem…

Our designer has worked up some nice layout that we need to implement. One of the features in the layout is a list of items that the user can select from. Obviously a ListBox. But the thing that caused problems, was the fact that it was supposed to show a compact information layout for all items except the selected item. The selected item should have a more verbose layout and some extra functionality. Initially that seemed like a tiny problem. That would just be a ItemTemplate with a VisualStateManager. Apparently not…!

More...

Silverlight 3 - MergedDictionaries

After having worked a while with Silverlight you realize that you often keep a lot of things in resources in your Xaml. Not only do you add Storyboards for your animations, but you often also add styles and templates, and some converters and so on. The resources all of the sudden start taking up most if the rows in your Xaml. It becomes hard to read. Especially since Silverlight is all about styling and templating controls, which results in large amounts of Xaml.

It is also hard to share resources. Say that you have these converters that you use in several of your controls. How do you solve that? Having them declared in multiple places is no good.

In Silverlight 2 there wasn’t much you could do. You would just have to have all of those resources in your Xaml, and if you wanted to share them, they had to be in the App.xaml file.

More...

flickrVIEWR – A flickr viewer in Silverlight – Part 3

I guess it is time to tie it all together and get the UI up and running for the flickrVIEWR. As you will notice, having built the viewmodels, the code for the UI is actually very simple. And the cool part is that there is no code in code behind at all.

But before I start creating the Xaml for the application, I’m going to hook up the viewmodel to the page and do a few little bits and pieces needed to get it all working.

More...

flickrVIEWR – A flickr viewer in Silverlight – Part 2

Hello again! It is time to go through the next phase in the development of the flickrVIEWR that I started a couple of days ago. The viewmodels. As usual I do build my Silverlight application using the MVVM pattern. I like this pattern a lot. Coming from an ASP.NET background, I think it offers a lot of nice features that I whish where available in general web development. I guess you do get some of the benefits and features by using MVC, but I have yet to try out doing that. And I will, I promise.

Anyhow…the viewmodels for the flickrVIEWR is not that complicated. Not at all. THhey have some small tricks up their sleeves, but nothing really cool. But before we get to the viewmodels I’m going to take a small detour via a service locator…

More...

flickrVIEWR – A flickr viewer in Silverlight – Part 1

I’m back! I’ve had my work up to my eyeballs the last couple of weeks. Apparently moving to the other side of the world and starting a new job takes a lot of time. So after that excuse, it is time to get started with my new project.

My fiancée has this blog where she blogs about our new life in NZ. And this is interesting to you because…? Well, it isn’t, but it is the reason for this blog post as well as a few more coming soon. On her blog, she posts pictures. These pictures are taken by her or me by a camera with several megapixels. That makes them too big for her blog. So she has to resize them before uploading them. This takes time and is annoying. So I offered to solve it in a somewhat more modern way. By using flickr. So she will upload her images to flickr and then use a little Silverlight application to show them on her blog. So that’s where this blog post is about…the flickrVIEWR…

More...

Creating custom controls in Silverlight - part 2

In part one, a button like control was created. It worked like a button, or at least a little. It was a square with a descriptive text and a brand new Click event. Unfortunately that doesn't really make it feel like a button. There is more to a button, especially in Silverlight and WPF. First off, a button normally gives some visual feedback to the user, confirming that it is pressed or that the button is hovering over it. That visual feedback is something that you find in most button implementation, whether it is in Windows Forms, HTML or WPF. The thing that is special with buttons in WPF and Silverlight is that the content of the button - in this case the descriptive text - can be anything. And I mean ANYTHING. It could be a Grid with several controls inside. Not that I would recommend doing some of the things that you CAN do, but it is possible. So in this part of the tutorial, the button will get visual feedback and support for complex content.

More...

Creating custom controls in Silverlight - part 1

After having written mhy previous entry about how to style and template controls, I guess it is a good time to have a look at how to create controls that are template- and styleable. (Can you write "template- and styleable"? Looks weird...well...I am swedish so I'm allowed to write less than perfect english) Unfortunately, due to my lack of imagination, I don't have a really cool control to build and show you. So instead I'm going to create a very limited control that will work more or less as a simple button.

More...