Sep 25 2009

The 2nd Place Winner - Telerik Silverlight Contest

Category:Bil@l @ 21:45

As you know there have been a Silverlight Contest moderated by Telerik for the best Silverlight application developed based on Telerik’s products.

My application took the 2nd place! Here are the results (http://www.telerik.com/community/silverlight-contest.aspx)

 

Thank you all for your support and vote!
Best Regards

 

 

The 1st place winner is

Ad-Hoc Reports for Enterprise Portfolio Simulator

Submitted by Kevin Jacobson from ProModel Corporation

Congratulations and thank you for your participation! Your project received the highest rating ( 3.4 of 4) and the $500 Amazon Gift Certificate goes to you! Please check your e-mail inbox for the award.

 

The 2nd place winner is

VBC Shortcuts

Developed by Bilal Haidar from Consolidated Contractors Company

Congratulations and thank you for your participation! Your project received the second best rating ( 3.1 of 4) and the $300 Amazon Gift Certificate goes to you! Please check your e-mail inbox for the award.

 

The 3rd place winners are

Both EGUMPP and House Hotel received rates of 2.8 of 4 after the community voting. Hence, their authors will share the third place award and will each receive a $100 Amazon Gift Certificate. Congratulations and thank you for your participation! Please check your e-mail boxes for the awards.

Tags:

Sep 21 2009

Telerik Sales Dashboard - Abide by Prism!

Category: Prism 2.0 | silverlight 2.0 | Telerik ControlsBil@l @ 22:32
There is no doubt that once you finish reading the Prism 2.0 (Composite Application Library) and try out all of the quick starts that accompany the guidance; it is a must to check out the Telerik Sales Dashboard. (http://demos.telerik.com/silverlight/salesdashboard)

Telerik not only pioneering in control development that targets the Microsoft .Net framework but also in educating developers all around the world with their extra efforts of:

  1. Code library
  2. Free software
  3. Extensive documentation
  4. Flash-Quick customer support
  5. Telerik labs
  6. Free Open-source projects

 

One of those major educating applications that Telerik delivers is the Telerik Sales Dashboard. It has been built on top of WPF and Silverlight keeping in mind the MVVM design pattern (Model-View-ViewModel) and Prism (Modularity, UI composition, global events, commanding, etc …)

You can download the source code to check it out and learn from it here (link)

In the whitepaper that accompanies in the Dashboard, I read the following:

PeriodSelector Module

This module handles the task of displaying a RadCalendar in a popup that can be used to select a range of dates for filtering data displayed in other modules. To close the popup containing the RadCalendar control when the user clicks outside of it, we subscribe to the MouseLeftButtonUp event of the RootVisual element of the application. We do not use the MouseLeftButtonDown event because it is used and handled internally by most controls and thus it is inappropriate for our purpose.

Also, we need to bind several properties of UI elements in this module to properties defined in the code-behind of the view, which are then in turn bound to properties in the viewmodel. This code-behind binding is necessary because the project requirements are not achievable with the XAML bindings available in Silverlight. This is a deviation from the Prism guidance, but, as already established, patterns should not be followed blindly if they block application requirements.

I found some code in the PeriodSelectorView.xaml.cs file that shouldn’t be present in a typical Prism application however, as it has been established in the Dashboard’s whitepaper, we shouldn’t follow a design pattern blindly if it blocks our work.

However, the code behind that was present could be replaced by implementing a new CommandBehavior that targets the RadCalendar. That was the first part of moving the code from code-behind into the PeriodSelectorViewModel.cs file. The other part is hooking up to the System.Windows.Application.Current.RootVisual.MouseLeftButtonUp  event inside the ViewModel file itself. The second part is easy and straight forward, so I will focus on the first one.


using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Data;
using System.Collections;

namespace Telerik.SalesDashboard.PeriodSelector
{
public partial class PeriodSelectorView : UserControl
{
public PeriodSelectorView(PeriodSelectorViewModel viewModel)
{
InitializeComponent();
this.DataContext = viewModel;

Binding b = new Binding();
b.Mode = BindingMode.TwoWay;
b.Path = new PropertyPath("CalendarSelectedDates");
this.SetBinding(PeriodSelectorView.SelectedDatesProperty, b);
calendar.SelectionChanged += (s, e) => this.SelectedDates = calendar.SelectedDates.ToList();
}

public IList SelectedDates
{
get
{
return (IList)this.GetValue(SelectedDatesProperty);
}
set
{
this.SetValue(SelectedDatesProperty, value);
}
}

// Using a DependencyProperty as the backing store for SelectedDates. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SelectedDatesProperty =
DependencyProperty.Register("SelectedDates", typeof(IList), typeof(PeriodSelectorView), null);
}
}

What has been done above is:

  1. Define SelectedDates as a Dependency property on the View itself
  2. Define CalendarSelectedDates as a property on the ViewModel class
  3. Define a Binding between the above two properties
  4. Hooking up to the SelectionChanged event of the RadCalendar to fill the SelectedDates property hence filling the CalendarSelectedDates property.

 

The above was a way to hook into RadCalendar control on the View to retrieve selected dates and pass back the value to the ViewModel.

Now, what I did was:

     1. Removing all code-behind from the View

     2. Define a new DelegateCommand as follows:     

public ICommand CalendarSelectedCommand { get; private set; }
      3.  Instantiate the DelegateCommand as follows:
        this.CalendarSelectedCommand = new DelegateCommand<IList>(OnCalendarSelectionChanged);
private void OnCalendarSelectionChanged(IList args)
{
this.CalendarSelectedDates = args;
}

             4. Implemented a new RadCalendarCommandBehavior class.  As you know in Prism the CommandBevaior class does many things among which are:

a. Adds Commanding behavior into a Control

b. Defines the Command, CommandParameter and CommandBehavior attached properties that can be hooked to a Control.

c. Plays the role of proxy between Command definition and Control that the command is defined on where it attaches to a specific event of a Control and defines the event handler for that event, so that when the event is fired, the command is being called and executed.

Now, firing the event of a Control causes the attached event handler defined inside the CommandBehavior to fire. Usually this event handler calls the Execute method of the CommandBehavior that internally delegates the call to the Execute method on the Command it defines as a Dependency property.

Thus you can see how important the CommandBehavior class in attaching a Command behavior into a Control.

The Prism ships with the ClickCommandBehavior class only. When I saw the code written inside PeriodSelectorView.xaml.cs I realized that all what I need is create a RadCalendarCommandBehavior.cs class that attaches a new Command into the RadCalendar class by hooking into the RadCalendar.SelectionChanged event.

The purpose is to fire a command on the RadCalendar that can be handled inside the PeriodSelectorViewModel.cs class where I can easily retrieve the selected dates and hence no need for the mediator SelectedDates dependency property inside the View and no need for accessing the RadCalendar.SelectionChanged event. The goal is the same however, the “how” is the different and I believe using commands is more elegant!

I will not go into the details of creating the RadCalendarCommandBehavior class, the code is straight forward based on Prism knowledge


using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Composite.Presentation.Commands;
using Telerik.Windows.Input;
using Telerik.Windows.Controls;
using System.Linq;
using System.Collections;

namespace Telerik.SalesDashboard.PeriodSelector
{
public class RadCalendarCommandBehavior : CommandBehaviorBase<RadCalendar>
{
public RadCalendarCommandBehavior(RadCalendar source)
: base(source)
{
source.SelectionChanged += new Telerik.Windows.Controls.SelectionChangedEventHandler(source_SelectionChanged);
}

void source_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
{
var calendar = sender as RadCalendar;
if (calendar != null)
{
this.Command.Execute(calendar.SelectedDates.ToList());
}
}
}

public static class SelectionChanged
{
private static readonly DependencyProperty SelectionChangedCommandBehaviorProperty = DependencyProperty.RegisterAttached(
"SelectionChangedCommandBehavior",
typeof(RadCalendarCommandBehavior),
typeof(SelectionChanged),
null);

public static readonly DependencyProperty CommandProperty = DependencyProperty.RegisterAttached(
"Command",
typeof(ICommand),
typeof(SelectionChanged),
new PropertyMetadata(OnSetCommandCallback));

public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.RegisterAttached(
"CommandParameter",
typeof(object),
typeof(SelectionChanged),
new PropertyMetadata(OnSetCommandParameterCallback));


public static void SetCommand(RadCalendar calendar, ICommand command)
{
calendar.SetValue(CommandProperty, command);
}

public static ICommand GetCommand(RadCalendar calendar)
{
return calendar.GetValue(CommandProperty) as ICommand;
}

public static void SetCommandParameter(RadCalendar calendar, object parameter)
{
calendar.SetValue(CommandParameterProperty, parameter);
}

public static object GetCommandParameter(RadCalendar calendar)
{
return calendar.GetValue(CommandParameterProperty);
}

private static void OnSetCommandCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
RadCalendar calendar = dependencyObject as RadCalendar;
if (calendar != null)
{
RadCalendarCommandBehavior behavior = GetOrCreateBehavior(calendar);
behavior.Command = e.NewValue as ICommand;
}
}

private static void OnSetCommandParameterCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
RadCalendar calendar = dependencyObject as RadCalendar;
if (calendar != null)
{
RadCalendarCommandBehavior behavior = GetOrCreateBehavior(calendar);
behavior.CommandParameter = e.NewValue;
}
}

private static RadCalendarCommandBehavior GetOrCreateBehavior(RadCalendar calendar)
{
RadCalendarCommandBehavior behavior = calendar.GetValue(SelectionChangedCommandBehaviorProperty) as RadCalendarCommandBehavior;
if (behavior == null)
{
behavior = new RadCalendarCommandBehavior(calendar);
calendar.SetValue(SelectionChangedCommandBehaviorProperty, behavior);
}

return behavior;
}
}
}

5. What is left is to add the following into the PeriodSelectorView.xaml:

a.       Add a new XML namespace reference into the header of the UserControl:

xmlns:MyCommands="clr-namespace:Telerik.SalesDashboard.PeriodSelector"
  <telerikInput:RadCalendar …  MyCommands:SelectionChanged.Command="{Binding CalendarSelectedCommand}"   … />

That’s all what you need to do to remove the code-behind from the PeriodSelectorView into the PeriodSelectorViewModel !

 

If you find that the above can be improved, or anything you find you couldn’t understand, or you think is not suitable, etc … Please don’t hesitate to contact me at: bhaidar @ gmail.com

Regards

 

Tags: , ,

Sep 17 2009

Telerik Silverlight Contest

Category:Bil@l @ 09:19

Dear all,

I participated lately in a Silverlight compeition moderated by Telerik corporation.

Voting has started and would like you to vote for my application "VBC Shortcuts - CCC"

 http://www.telerik.com/community/silverlight-contest.aspx

Thank you for your help and support.
Regards

Tags:

Sep 10 2009

TFS Work Item Manager &amp; TFS Project Dashboard Beta

Category: TelerikBil@l @ 16:09

Telerik release two new FREE products:

  1. TFS Work Item Manager
  2. TGS Project Dashboard

Get more details from here: TFS Work Item Manager and TFS Project Dashboard 

 

Regards

 

 

Tags:

Aug 26 2009

Anonymous Types in Silverlight 2.0

Category: silverlight 2.0Bil@l @ 17:03

If you are querying a collection in Silverlight 2.0 using LINQ and you want to extract a subset of the properties on the queries collection objects, you cannot make use of Anonymous Types in LINQ. For instance the following query won't return any value:

    public class Employee
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }

            List<Employee> employees = new List<Employee>();
            employees.Add(new Employee { FirstName = "Bilal", LastName = "Haidar" });
            employees.Add(new Employee { FirstName = "Bill", LastName = "Gates" });

            var results = from emp in employees
                          select new { FirstName = emp.FirstName };

results will be empty as Anonymous Types are not supported.

A solution can be done by disecting your domain objects in this case a very simple object (Employee) into smaller structs

    public struct SubEmployee
    {
        public string FirstName { get; set; }
    }

And the query could be as follows:

            IEnumerable<SubEmployee> results = from emp in employees
                          select new SubEmployee{ FirstName = emp.FirstName };

 

You can have as many structs as you want to ease your work.

Hope this tip helps!
Regards

Tags:

Aug 19 2009

The remote server returned an error: NotFound. -- Silverlight Exception

Category:Bil@l @ 16:01

While working on a Silverlight application and you face such exception: "The remote server returned an error: NotFound."

You should check this blog post:

Silverlight and WCF Essentials - Fiddler

 

Regards

 

Tags:

Aug 18 2009

Columns &amp; Rows - Silverlight Series on DataGrid - ASPNETPRO

Category:Bil@l @ 06:20

Now you can view most of the series of my articles on Silverlight DataGrid hosted by ASPNETPRO magazine:

Columns & Rows Part I: Silverlight 2.0 DataGrid Properties

Columns & Rows Part II: Silverlight 2.0 DataGrid Columns

Columns & Rows Part III: Working with DataGrid Master/Detail

Columns & Rows Part IV: Silverlight 2.0 DataGrid CRUD Operations

 

Hope you enjoy reading them.

Regards

Tags:

Aug 16 2009

RadControls Silverlight 3 Official with Q2 2009 SP1

Category: silverlight 3.0Bil@l @ 19:28

Telerik RadControls for Silverlight3 are here with the latest 2009 Q2 SP1 release!

Read more here:

RadControls Silverlight 3 Official with Q2 2009 SP1

 

Enjoy Silverlightening......

Tags:

Jun 27 2009

Think out of the box

Category: PersonalBil@l @ 11:35


I choose to help a friend ....... but for sure I was thinking inside the box!!!


You are driving down the road in your car on a wild,
stormy night, when you pass by a bus stop and you see three people
waiting for the bus:

 
1. An old lady who looks as if she is about to die.
 
2. An old friend who once saved your life.

3. The perfect partner you have been dreaming about.

 
Which one would you choose to offer a ride to, knowing that
there could only be one passenger in your car? Think before you continue reading.

 
This is a moral/ethical dilemma that was once actually used as part of a job
application. You could pick up the old lady, because she is going to die, and thus you should save her first. Or you could take the old friend because he once saved your life, and this would be the perfect chance to pay him back. However, you may never be able to find your perfect mate again.

 
YOU WON 'T
BELIEVE THIS...................

 
 
The candidate who was hired (out of 200 applicants) had no trouble coming up with his answer. He simply answered: 'I would give the car keys to my   old friend and let him take the lady to the hospital. I would stay behind and wait for the bus with the partner of my dreams.'

 
Sometimes, we gain more if we are able to give up our stubborn thought   limitations.
 
Never forget to 'Think Outside of the Box.'

Tags:

Jun 23 2009

Columns &amp; Rows: Part II Silverlight 2.0 DataGrid Columns

Category: silverlight 2.0Bil@l @ 07:21

Here is the second installment of my series Columns and Rows on the ASPNETPRO magazine.

Columns & Rows: Part II  Silverlight 2.0 DataGrid Columns

If you haven't yet read the first installment, you can read the blog post here: Columns & Rows Part I: Silverlight 2.0 DataGrid Properties.

 

Hope you enjoy it!
Regards

 

Tags: