Thursday, February 3, 2011

Double Click for ListBox - Silverlight

 

Following is the code that I follow for getting my code working for the doubleclick event for a listbox event in silverlight

First I declare 2 field/variables at Form level so that they are accessible through out the form/silverlight page like this:

Dim t1 As New DateTime
Dim t2 As New Integer

Then I write the following code in the MouseUp or left mouse up event.

Dim n As New DateTime
        n = Now
        Dim c As Double = DateDiff(DateInterval.Second, t1, n)
        If DateDiff(DateInterval.Second, t1, n) < 1 Then
            If n.Millisecond - t1.Millisecond < 100 Then
                If t2 = ListBox1.SelectedIndex Then
                    'Double click event code here
                    MessageBox.Show("Working")
                Else
                    'Single Click event code here
                End If
            End If
        End If
        t1 = Now
        t2 = ListBox1.SelectedIndex

It works well, I use it.

Property VS Field –XAML Binding- Silverlight

After a brain storming and internet searching for hours together, I came to know that Silverlight do not bind the data from field, but it binds only property.  Following is the declaration methodology

FIeld Dim fullname as string
Property

Property FullName() As String
            Get
                Return namee
            End Get
            Set(ByVal value As String)
                namee = value
            End Set
End Property

Here ‘namee’ is a field declared in the class or etc.

Following the XAML binding to be used:

<sdk:Label Height="28" Content="{Binding FullName}"/>

Hence during the code we can just use Itemsourcebinding for multivalue binding or if the value is only since like in this case then we use dataContext binding, but itemsourcebinding would do the trick too.

Friday, January 14, 2011

Experience With Silverlight

I was always excited of doing codes as they look like puzzles, this time Microsoft has gone  further more and brought more colors to them.

Silverlight is very fascinating, it can make us think beyond our limitations of programming.  Earlier, or till few years back, programming a button is just to add a text or to add a image at max to it, but with the advent of Silverlight, I can display an entire webpage or a Data grid View control inside a button with custom animations.

It is like programming code with EXPRESSION.