|
There are many great changes in Beta 2, and some are designed to make Silverlight more like WPF. One side effect of this is that event bubbling has changed just a bit and that bit breaks some of the examples I love to use. In Beta 1, the distinction was that all the controls handled their own click events but the more primitive events such as many of the mouse events were allowed to bubble. This allowed for interesting if not terribly useful demonstrations in which I placed a check box inside a button and was able to demonstrate that if I were to use the click event on the check box the button would never see the click, but if I used a MouseLeftButtonDown, hey! Presto! the button did see the event. This has now changed in Beta 2 to make Silverlight behave more like WPF. By and large (other than breaking my demo) this is a good thing. The consistency now is that objects that directly derive from UI element do support event bubbling for the mouse events (that is, Ellipse, Glyphs, Image, InkPresenter, Line, MediaElement, Path, Polygon, Polyline, Rectangle and TextBlock.) In addition, the container classes do. Thus, if you set up the following bizarre application in which you have a grid, with a grid in it, that contains a stack panel that in turn contains a rectangle, a TextBlock, a check box, a button and a listbox (the last to show the results)… <UserControl x:Class= "EventBubbling.Page" xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml" Width= "400" Height= "800" > <Grid x:Name= "LayoutRoot" Background= "White" > <Grid x:Name= "InterimGrid" > <StackPanel x:Name= "myStackPanel" Orientation= "Vertical" > <Rectangle x:Name= "myRect" Width= "30" Height= "30" Fill= "Blue" Stroke= "Red" StrokeThickness= "2" Margin= "0,10,0,10" /> <TextBlock x:Name= "myTextBlock" Text= "Hello" HorizontalAlignment= "Center" FontSize= "14" Margin= "0,10,0,10" /> <CheckBox x:Name= "myCheckBox" Content= "Check Me" Width= "80" Height= "40" Margin= "0,10,0,10" HorizontalAlignment= "Center" /> <Button x:Name= "myButton" Content= "TinyButton" Height= "30"...
|