none
Windows Phone如何添加List View的组标题按钮的事件? RRS feed

  • 问题

  • 在教程http://msdn.microsoft.com/zh-cn/library/windows/apps/xaml/hh780627.aspx中,如何将组按钮添加点击事件?

    部分代码:

    App.Xaml:

    <Application
        x:Class="ItemsControlGroupingSnippets.App"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:ItemsControlGroupingSnippets">
    
        <Application.Resources>
            <ResourceDictionary>
                <DataTemplate x:Key="listViewItemTemplate">
                    <StackPanel Width="320" Margin="10">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Name}" FontWeight="Bold" Style="{StaticResource BaseTextBlockStyle}"
                           Margin="2,0,0,0"/>
                            <TextBlock Text="{Binding DueDate}" Style="{StaticResource BodyTextBlockStyle}" TextWrapping="NoWrap"
                           Margin="20,0,0,0"/>
                        </StackPanel>
                        <CheckBox Content="Complete" IsChecked="{Binding Complete}" IsEnabled="False"/>
                    </StackPanel>
                </DataTemplate>
    
                <GroupStyle x:Key="listViewGroupStyle">
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Background="LightGray"  >
                                <TextBlock Text='{Binding Key}' Foreground="Black" Margin="10"
                               Style="{StaticResource SubheaderTextBlockStyle}" />
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
            </ResourceDictionary>
        </Application.Resources>
    </Application>
    

    MainPage.Xaml:

            <ListView ItemsSource="{Binding Source={StaticResource cvsActivities}}"
              ItemTemplate="{StaticResource listViewItemTemplate}"
              GroupStyleSelector="{StaticResource listGroupStyleSelector}"
              Margin="120" Width="320"/>

    MainPage.xaml.cs:

        public class ListGroupStyleSelector : GroupStyleSelector
        {
            protected override GroupStyle SelectGroupStyleCore(object group, uint level)
            {
                return (GroupStyle)App.Current.Resources["listViewGroupStyle"];
            }
        }

    2014年8月25日 7:15

答案

  • 已经解决,代码:

                        <ListView>
                            <ListView.GroupStyle>
                                <GroupStyle>
                                    <GroupStyle.HeaderTemplate>
                                        <DataTemplate>
                                            <Grid Tapped="Grid_Tapped">
                                                <!--内容-->
                                            </Grid>
                                        </DataTemplate>
                                    </GroupStyle.HeaderTemplate>
                                </GroupStyle>
                            </ListView.GroupStyle>
                        </ListView>

    2014年8月25日 12:15