可点击的表格单元格而不是Windows通用应用程序中的行

时间:2015-11-28 14:34:14

标签: xaml win-universal-app clickable

我使用ListView在通用Windows应用程序中显示数据表。 现在每行都可以点击,但我希望每个Cell都可以点击。

这是我的DataTemplate:

 <DataTemplate x:Key="TaskTemplate">
        <Grid Background="white" Height="43" Width="Auto">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"></RowDefinition>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="2*"></ColumnDefinition>
                <ColumnDefinition Width="2*"></ColumnDefinition>
                <ColumnDefinition Width="1*"></ColumnDefinition>
                <ColumnDefinition Width="1*"></ColumnDefinition>
                <ColumnDefinition Width="2*"></ColumnDefinition>
                <ColumnDefinition Width="2*"></ColumnDefinition>
                <ColumnDefinition Width="2*"></ColumnDefinition>
                <ColumnDefinition Width="2*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <TextBlock Margin="10,8,8,8" Style="{StaticResource CrisamTitleTextBlockStyle}" Text="{Binding Name}" Grid.Column="0" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap"/>

            <TextBlock Margin="10,8,8,8"  Style="{StaticResource CrisamTitleTextBlockStyle}" Text="{Binding TaskType}" Grid.Column="1" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap"/>

            <TextBlock Margin="10,8,8,8" Style="{StaticResource CrisamTitleTextBlockStyle}" Text="{Binding Priority}" Grid.Column="2" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap"/>

            <TextBlock Margin="10,8,8,8"  Style="{StaticResource CrisamTitleTextBlockStyle}" Text="{Binding State}" Grid.Column="3" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap"/>

            <TextBlock Margin="10,8,8,8"  Style="{StaticResource CrisamTitleTextBlockStyle}" Text="{Binding StartDate}" Grid.Column="4" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap"/>

            <TextBlock Margin="10,8,8,8"  Style="{StaticResource CrisamTitleTextBlockStyle}" Text="{Binding EndDate}" Grid.Column="5" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap"/>

            <TextBlock Margin="10,8,8,8"  Style="{StaticResource CrisamTitleTextBlockStyle}" Text="{Binding Officer}" Grid.Column="6" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap"/>

            <TextBlock Margin="10,8,8,8"  Style="{StaticResource CrisamTitleTextBlockStyle}" Text="{Binding Completed}" Grid.Column="7" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap"/>
        </Grid>
    </DataTemplate>

这是ListView:

<ListView Width="auto" Grid.Row="2" 
        x:Name="taskGridView"
        Padding="20"
        AutomationProperties.AutomationId="TaskGridView"
        AutomationProperties.Name="Tasks In Group"
        SelectionMode="None"
        IsSwipeEnabled="false"
        IsItemClickEnabled="True"
        ItemsSource="{Binding Collection}"
        ItemTemplate="{StaticResource TaskTemplate}"
        HorizontalContentAlignment="Center"
        HeaderTemplate="{StaticResource TaskHeaderTemplate}"
        >
        <Interactivity:Interaction.Behaviors>
            <Behaviors:ListViewEventBehavior/>
        </Interactivity:Interaction.Behaviors>

            <ListView.Resources>

        </ListView.Resources>
        <ListView.ItemContainerStyle>
            <StaticResource ResourceKey="CrisamListViewItemContainerStyle"/>
        </ListView.ItemContainerStyle>
    </ListView>

这是ListViewItemContainerStyle:

            <Style x:Key="CrisamListViewItemContainerStyle" TargetType="ListViewItem">
            <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
            <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}"/>
            <Setter Property="TabNavigation" Value="Local"/>
            <Setter Property="IsHoldingEnabled" Value="True"/>
            <Setter Property="Padding" Value="0"/>

            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="MinWidth" Value="{ThemeResource ListViewItemMinWidth}"/>
            <Setter Property="MinHeight" Value="{ThemeResource ListViewItemMinHeight}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListViewItem">
                        <ListViewItemPresenter
                            CheckBrush="DimGray"
                            ContentMargin="{TemplateBinding Padding}"
                            CheckMode="Overlay"
                            ContentTransitions="{TemplateBinding ContentTransitions}"
                            CheckBoxBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
                            DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}"
                            DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}"
                            DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}"
                            DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}"
                            FocusBorderBrush="{ThemeResource SystemControlForegroundAltHighBrush}"
                            FocusSecondaryBorderBrush="{ThemeResource SystemControlForegroundBaseHighBrush}"
                            BorderThickness="2" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                            PointerOverForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
                            PressedBackground="{ThemeResource SystemControlHighlightListMediumBrush}"
                            PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}"
                            PointerOverBackground="{ThemeResource SystemControlHighlightListLowBrush}"
                            ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
                            SelectedPressedBackground="{ThemeResource SystemControlHighlightListAccentHighBrush}"
                            SelectionCheckMarkVisualEnabled="True"
                            SelectedForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
                            SelectedPointerOverBackground="{ThemeResource SystemControlHighlightListAccentMediumBrush}"
                            SelectedBackground="{ThemeResource SystemControlHighlightListAccentLowBrush}"
                            VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

结果如下: result

0 个答案:

没有答案