Monday, December 12, 2011

Silverlight Event

In Silverlight MSDB always says that the event are bubbled
Taken from MSDN
http://msdn.microsoft.com/en-us/library/cc189018%28v=vs.95%29.aspx

WPF supports an analogous "tunnelling" routing strategy, whereby the root of a page / object tree has the first chance to handle a routed event, and the event then "tunnels" down the object tree toward its event source. Silverlight does not use "tunnelling" routed events. Events in Silverlight either follow the "bubbling" routing strategy (and are referred to as routed events) or do not route at all. There are also other API-level differences in routed event behaviour between Silverlight and WPF.

Which means that in silver light there is no tunnelling.....

But with the below sample I am trying to show a bug in Silverlight Datagrid
when we subscribe the events for the selected item event.

In the below example , I have created a Data Grid which subscribe the selected item event, and the data grid have 2 columns .One is defined as DataGridTemplateColumn and another is a DataGridTextColumn.In the DataGridTemplateColumn I have placed a checkbox and subscribe the click event ...

Turn on the debugger and see when we clicked on the check box .....Which event got fired.....






                  




                       









namespace SilverlightApplication1
{
   public partial class MainPage : UserControl
    {
      public MainPage()
        {
          InitializeComponent();
          this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

     void MainPage_Loaded(object sender, RoutedEventArgs e)
      {
       List lstTest = new List();
       lstTest.Add(new Test { CheckFlag = true, StringCaption = "1" });
       lstTest.Add(new Test { CheckFlag = true, StringCaption = "2" });
       lstTest.Add(new Test { CheckFlag = true, StringCaption = "3" });
       lstTest.Add(new Test { CheckFlag = true, StringCaption = "4" });
       lstTest.Add(new Test { CheckFlag = true, StringCaption = "5" });
       lstTest.Add(new Test { CheckFlag = true, StringCaption = "6" });
       dgTest.ItemsSource = lstTest;
      }

   private void dgTest_SelectionChanged(object sender,SelectionChangedEventArgs  e)
    {

     }

  private void CheckBox_Click(object sender, RoutedEventArgs e)
   {

    }
}
public class Test
 {
  public bool CheckFlag { get; set; }
   public string StringCaption { get; set; }
 }
}

Looking into this and try to understand this whether this is a bubbling or not ..

0 comments:

Post a Comment