Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Event timing
5 replies. Latest Post by Mog Liang - MSFT on November 5, 2009.
(0)
dob_xml
Member
7 points
29 Posts
11-03-2009 6:22 AM |
Looking at the sample provided here (I couldn't add comment on the post at web site as it was timing out)
http://dotnetspeak.com/index.php/2009/10/silverlight-3-collectionviewsource-and-navigation/
I have 2 questions
1) In ProductList.xaml.cs I added a button and a handler
1 private void AddNewGroupButton_Click(object sender, RoutedEventArgs e) 2 { 3 CollectionViewSource viewSource = Resources["ViewSource"] as CollectionViewSource; 4 if (viewSource != null) 5 { 6 viewSource.GroupDescriptions.Add(new PropertyGroupDescription("Category")); 7 } 8 }
When this executes I get a "Specified method is not supported." exception.Can anyone exaplain that?
2) Place breakpoints in ProductList.xaml.cs at
NavigationService.Navigate(((Button)sender).Tag as Uri);(in Button_Click)
andProduct product = e.Item as Product; (in MyFilter)
Now run the app and click on a Details button. I have observed the BP in MyFilter is hit then I continue and the BP in Button_Click is not hit. I click the Details button again and the BP in MyFilter is not hit and the Button_Click BP is hit. This observation is not consistent. Can anyone explain why this is? A event timing thing?
bryant
Star
9937 points
1,629 Posts
11-03-2009 6:42 PM |
If you read the documentation on GroupDescriptions you will see:
This property is not implemented. Accessing it will cause a NotSupportedException.
What does your xaml look like? Sounds like maybe you have the events wired up backwards.
11-04-2009 4:09 AM |
Thanks, I spotted that documentation last night. I need to be more careful when reading WPF Vs Silverlight XAML
With regard to the events it works fine and only behaves oddly when I introduce breakpoints. The XAML is shown below but you can get the full code from the url in the original question
1 <UserControl.Resources> 2 <CollectionViewSource Source="{StaticResource ProductList}" 3 x:Key="ViewSource" 4 Filter="MyFilter" 5 /> 6 </UserControl.Resources> 7 <Grid x:Name="LayoutRoot"> 8 <Grid.RowDefinitions> 9 <RowDefinition Height="Auto"/> 10 <RowDefinition Height="*"/> 11 </Grid.RowDefinitions> 12 <Grid.ColumnDefinitions> 13 <ColumnDefinition Width="Auto"/> 14 <ColumnDefinition Width="*"/> 15 </Grid.ColumnDefinitions> 16 <TextBlock Text="Fitler:"/> 17 <TextBox Grid.Column="1" TextChanged="TextBox_TextChanged" x:Name="FilterBox" Text=""/> 18 <data:DataGrid 19 ItemsSource="{Binding Source={StaticResource ViewSource}}" 20 AutoGenerateColumns="False" 21 Grid.Row="1" 22 Grid.ColumnSpan="2"> 23 <data:DataGrid.Columns> 24 <data:DataGridTextColumn Binding="{Binding ProductId}" Header="Product ID"/> 25 <data:DataGridTextColumn Binding="{Binding ProductName}" Header="Product Name"/> 26 <data:DataGridTextColumn Binding="{Binding ProductDescription}" Header="Description"/> 27 <data:DataGridTextColumn Binding="{Binding Category}" Header="Category"/> 28 <data:DataGridTemplateColumn> 29 <data:DataGridTemplateColumn.CellTemplate> 30 <DataTemplate> 31 <Button Content="Details" Tag="{Binding Url}" Click="Button_Click"/> 32 </DataTemplate> 33 </data:DataGridTemplateColumn.CellTemplate> 34 </data:DataGridTemplateColumn> 35 </data:DataGrid.Columns> 36 </data:DataGrid> 37 <Button x:Name="AddNewGroupButton" 38 Content="Add Group" 39 Click="AddNewGroupButton_Click"/> 40 </Grid>
Mog Lian...
All-Star
16023 points
1,553 Posts
11-05-2009 2:00 AM |
Hi,
Button click event is composed of two event Mouseleftbuttondown and mouseleftbuttonup. before two event fire completely, datagrid selectionchanged fired which would call the source filter. at this time, your breakpoint pause the application and disturb button event logic, so the click event didn't fire.
This is the whole story. the firing sequence is not always like I said, so you noticed the inconsistent behavior.
Anyway, this is caused by breakpoint, you needn't be worry about that.
Thanks,
11-05-2009 4:42 AM |
Thanks for the reply. Can you provide information on how I can track/learn more about the firing sequence? For instance I did not know that a button click was composed of two other events.
What logic is used to process the events? Are they queued? Can they time out? Can one cancel another?
I think this is very important information to share with the community.
It is possible to write code inside an event handler "expecting" it to be fired in a particluar sequence with respect to other events. We need to know more about firing sequence especially when we have complicated compositions (more than just a button on a grid).
11-05-2009 8:53 PM |
I noticed that when click button but event doesnt fire, the button stay in pressed appearance, then I guess that mouseleftbuttondown event may be ingored. For click event implementation, I use Reflector to check the code.