Silverlight Pagination Control – bug fixed

There were a couple of bugs in how the number of pages were computed, the problem is now solved and the solution is updated, see the article at: Silverlight: a generic Pagination Control

I start to believe that I really have to test my controls a little more before posting them :D, consider also that I’m using most of my code in production applications, so these small project are always subject to changes and fix as new feature can be introduced from time to time.

If you try my code and find some bug in it, don’t be shy and don’t hesitate to post your fixes they can save me some time during everyday’s life.

Maybe can be useful to have a page on the site in which I’ll regroup all the small projects with their corresponding version number…but to be honest I’m a bit lazy to do it right now.

Technorati Tags: ,

Related Content


DotNetKicks and DZone Live Writer plugins

Beeing a noob blogger as I am, I continously discover something new. Some time ago my friend Alkampfer introduced me to the DotNetKicks world, it’s an aggregator site for those who don’t know used mainly by developers. Recently I discovered DZone which do the same job. Now I use them both regularly to keep trace of what happens around and find interesting articles to read.

But adding the code to link manually both can be boring, so I want to thank John Papa for his great Live Writer plugins that covers both worlds, you can reach his posts on the plugins starting from this link: http://johnpapa.net/all/dzone-plugin-for-windows-live-writer/

Using the updated versions of those plugin + the new beta of Live Writer both the anchors will be added at the post footer automatically without anything else to do…that’s a lot of time saved.

Silverlight: a generic Pagination Control

The default silverlight controls like DataGrid and ItemsControl come without a default paging mechanism like we have in ASP.NET, so this article will be forcused in developing a generic Pager Control in Silverlight. This is what we want to obtain:

SilverlightPagination1

I was lurking around looking for some informations on ASP.NET MVC, and I found two interesting articles on how to do pagination in ASP.NET MVC (http://blog.wekeroad.com/2007/12/10/aspnet-mvc-pagedlistt/ and http://code-inside.de/blog-in/2008/04/08/aspnet-mvc-pagination-view-user-control/), the tecnique seemed inetersting and I decided to use it in my pager control.

The control will be divided in 2 major areas, the pager itself a series of helper classes that will give us different views of the data (a single 'page' of data can be tought as a view) and the selection control (which will use the pager) that will display a series of buttons to choose which page of data to display.

Let's start with the pager, since the control do not have to know the exact type of the data for which he will provide the paging features we need to define two interfaces: one that represent the view of the data we want to display (the actual page displayed) and another that will be the functions exposed by the pager itself.

Here we have some snippets of code taken from the two interfaces:

GMail: Account Suspended = Account Forever Lost

In the first days of August I have created a brand new GMail account to use some of thervices Google provided...15 to 20 days later I had to access that account via web interface...unfortunately happened that I had forgot the password and after some attempt the system blocked my account.

I tried every so-called password recovery procedure that google has, tried to fill every form they provide with all the in formation I could remind and this was their automated reply:

"Thank you for your report. The account in question is disabled, and we
can't provide you with access to it. For more information about disabled
accounts, please visit the following link in the Google Accounts Help
Center: ... etc etc..."

which basically brought me to the same password recovery shit tried before.

I tried to look in their user assistance forum and saw that many many people have the same problem...after an account block it seems there's no way to resume it, writing to the assistance center is pointless..they don't reply anyway.

As you can immagine I'm a bit disappointed by the low quality of the service provided by google with GMail, I have many free emails account made with different companies that offers similar services and it never happened something like this.

Silverlight: Custom Buttons with Templates

Sometimes you want to define a consistent look for all you application and maybe you completely replace the template of a control (lets say...a button :D), then you want to use the same template with small variations (colors or images for example).

Lets say we have realized the usual round button with a gradient background and that you want to use different colors which have different meanings for the interface, the same principles apply to any other control or custom controls.

Actually you can do it all just defining styles in the App.xaml file, like this:

Silverlight: simulate a 'Windows' desktop application - part 1

As my first real experiment in building a Silverlight control, I wanted to realize something that could permit me to offer to the users a windows-like experience application hosted in the browser, so I started wondering how difficult was to implement a control that could host other silverlight control and even pages, this control should then act as a 'real' window and can be dragged on the surface (over other controls) and with resizing and closing capabilities, plus I want to give the Window a look similar to WIndows Vista Aero Desktop windows.

To be honest Silverlight is very flexible and its templating capabilities made the task a lot simplier than I tought at start, here's what we want to obtain:

SimulatingWindows1

This 'tutorial' will be divided in a series of 3 articles that describe:

  1. the basic idea and the creation of the control.
  2. implementation of dragging capabilities.
  3. implementation of resizing capabilities.

The source code that comes with each part will however include the complete example solution (since I'm too lazy to divide it in parts), so let's get started.

There are a bunch of articles out there that describes how to create a user control and how to skin it so I won't dig deep in that; one of the best and very simple to follow is: 'Craft Custom Controls for SIlverlight 2' by Jeff Prosise (http://msdn.microsoft.com/en-us/magazine/cc721611.aspx), so use it as you main reference in creating your new controls.

Let's point out the ideas that are behind the Window control:

To move the windows around and resize them freely we need to use the 'Canvas trick' and place an outside Canvas that encapsulate any other controls on the page in which we want to use the windows, this is a must since I've not yet found a way to inject dinamically a canvas on a preexisting page.

We then need 2 classes basically: a Window class that will handle the windows features and a WindowManager class that act like a supervisor for all the windows hosted on the page, this is a very simple class that act like the operating system do with normal windows...it creates them and when he receive the WM_CLOSE message (placed in the message pump by the windows) it closes them.

We are forced to implement our own mecanics since silverlight do not offer any native way (yet) to handle windows like we want to do, we also do not have a message pump to use so we will use the notification events that will be raised by the Window.

The Windows control is quite simple to realize at start, its main template will be contained in the Generic.xaml file of the solution and will be automatically loaded for each instance since we specify the DefaultStyleKey property in the constructor of the class, the template will define some pure graphical controls and 4 named controls that will represent:

  • the window surface itself - used for resizing the control
  • the caption bar - used for dragging the window around
  • the caption bar text
  • the close button.

The style for the close button is defined in the App.xaml file and redefines the template of a normal silverlight button, you can use Expression Blend to take a look at both files and edit the templates.

We will get a reference to those control when the template will be loaded by the runtime (just before rendering it) in the overridden OnApplyTemplate() function: