Sunday, August 30, 2009

Default Focus Behavior

I would love to share with you guys about Default Focus Behavior which I just created an hour ago because I thought this behavior would be very handy.

With this behavior, we would be able to set focus to any controls when we trigger any control events.

For example, whenever we click the button, we want to textbox got focused, or when we select the Option 1 for the very first time, the textbox will get focused as below image


Click the icon below for the source code

Hopes this helpful :)Technorati Tags:

Saturday, August 29, 2009

TextWraping in Silverlight

Just a little thing I came across when I am trying to set TextWraping property for a TextBox, but the text doesn't seem to be wrapped. Then I realized if the TextBox is setting with TextWraping greater than 1, the text won't be wrapped. Just a little thing to keep in mind :)

Thursday, August 20, 2009

Datagrid Missing Binding Error

I have run into this silly mistake, and it took me 2 hours to figure it out :(

I am writing it down here for my own reference, and if you ever ran into this problem, hope that this can help you fix your problem quickly.

The problem is I had a datagrid column with the Header but not the Binding, for example

This will cause the below error at runtime

Datagrid Missing Binding Error

To fix it, all I had to do is to put the Binding in it

Hope this helps

Monday, August 17, 2009

UpperCase Behavior

I was asked to create a TextBox input which has only UpperCase letters. After a bit of research, I have found this article which has inspired me to come up with this solution. As we all know that Behavior is a cool stuff in Silverlight 3, so I decided to use the concept from that article and create a Behavior which detects all the key and uppercase it. Feel free to download the source code and have a play with it.

Wednesday, June 17, 2009


I've read this article about FocusManager. I think it could come handy sometimes when you want to know what element has focus. FocusManager class which can be found in the System.Windows.Input namespace. Below is the sample of how to use it

The FocusManager class has only one static method:

<span class="kwrd">public</span> <span class="kwrd">static</span> Object GetFocusedElement();

Using the FocusManager is easy. Here’s a small example of a possible usage:

var focusedElement = FocusManager.GetFocusedElement() as Control;
if (focusedElement != null)
Output.Text = focusedElement.Name;

One last note: The FocusManager class is also available in the “normal” .NET Framework 3.0 or later.

Tuesday, June 9, 2009

Binding for Converter Parameter

I have come across the situation where I need to do some Binding for ConverterParameter. Something like

I have done lots of research, and I found out that its impossible to do binding for ConverterParameter.
So I came up with the Solution. I created the Converter but inherited from FrameworkElement

public class ShowDeleteServiceConverter : FrameworkElement, IValueConverter

In the converter class, I created a dependency property

Now, I can do the Binding as usual


It might not be the best solution, but it works for me so far. If you have any idea, feel free to drop me comments.


Monday, January 26, 2009

How to Change the Startup Class

Another great tip from Mike Snow. Read the original article here 

When a Silverlight application is launched the entry point is a class that inherits from System.Windows.Application. By default, when you create a new Silverlight application project, this would be your App class which gets defined in App.xaml.cs. You can, however, change which startup class you want to use. In fact, if you do not plan to use XAML at all you can reduce the size of your application by deleting the Page and App classes including the XAML and code behind files. 

To accomplish this follow these steps: 

Step 1. Create a new Silverlight application project adding a new web project to host the Silverlight app. 

Step 2. Delete App.xaml and Page.xaml (the CS files will be deleted also). 

Step 3. Create a new class and call it StartupTest.cs 

Step 4. Modify your new class to inherit from Application as seen here:

public class StartupTest : Application


    public StartupTest()




Step 5. Right click on your Silverlight application project in the Solution Explorer of VS. From the context menu choose Properties. This will bring up the Properties dialog. Click on the Silverlight tab at the top-left and change the Startup object to be your class as seen circled here: image

Step 6. Go back to your StartupTest class. Add an event to monitor for when the application has started. You don’t want to do anything until after this event has started.

public class StartupTest : Application


    public StartupTest()


        this.Startup += new StartupEventHandler(StartupTest_Startup);




    void StartupTest_Startup(object sender, StartupEventArgs e)




Step 7. The Application.RootVisual is root pointer to the main application UI. You will need to create this object to point an object such as a Grid or Canvas control. Once created, you can add additional controls to the children as you see fit. In the example below, I have created a Canvas as the root and configured its background color to be black, its width to be 800 and height to be 600. Also, I have added a Textbox to the Canvas control.

void StartupTest_Startup(object sender, StartupEventArgs e)


    this.RootVisual = new Canvas();


    ((Canvas)this.RootVisual).Width = 800;

    ((Canvas)this.RootVisual).Height = 600;

    ((Canvas)this.RootVisual).Background = new SolidColorBrush(Colors.Black);


    TextBlock tb = new TextBlock();

    tb.Foreground = new SolidColorBrush(Colors.White);

    tb.FontSize = 20;

    tb.Text = "NO XAML NEEDED!!!";




Step 8. Run the application and you will see the following image rendered in your browser: image Technorati Tags:

Thursday, January 1, 2009

How to Create A Badge Of Your Facebook

Create a Badge From a Template
  1. Log into your facebook account
  2. Click on the "My Profile" link to view your current profile after you have logged in.
  3. Select the "Create a Profile Badge" link that can be found on your profile.
  4. Choose a template to help create your badge. A photo badge showcases your most recent photo uploads. The Signature Badge has your contact information and is ideal for email and forum signatures. The blog badge is a great addition to your external Web site or blog.
  5. Set the preferences for your template. While they may vary slightly, you must select a layout (Horizontal or Vertical) and a format (Image or JavaScript) for each template.
  6. Finish making changes to your badge and click "Save" to get directions for posting your badge. You will need to copy and paste the provided code into the Web site where you want the badge to appear.
Create a Custom Badge
  1. Show your individuality by choosing to "Create a Badge" from the "Create a Profile Badge" page.
  2. Set the basic layout and format.
  3. Add any items from the drop-down menu that you want to include in your badge. Click the "Add Item" button to add it to your badge. You may add more than one item. With no template, you can add anything you want to your badge. It will preview as you make additions.
  4. Hit the "Save" button to complete your badge and get the necessary code to post it.
Technorati Tags: ,