禁用DataGrid组标题的可折叠性

我有一个带有在xaml中定义的DataGrid的UWP应用程序。

DataGrid包含分组的数据。当显示时,可以单击组标题左侧的朝下克拉,从而导致该组折叠。据我所知,这是我们没有明确要求的默认行为。

我的客户不喜欢这个,希望我删除该功能。我该怎么办?

liangpengju20080809 回答:禁用DataGrid组标题的可折叠性

您可以通过修改DataGridRowGroupHeader.HeaderStyle来禁用该功能。简单的方法是将IsHitTestVisible添加到False。这将禁用扩展器,因此该组不会崩溃。

<controls:DataGrid>
   <controls:DataGrid.RowGroupHeaderStyles>
     <Style TargetType="controls:DataGridRowGroupHeader">     
        <Setter Property="IsHitTestVisible" Value="False"/>
     </Style>
   </controls:DataGrid.RowGroupHeaderStyles>
</controls:DataGrid>

编辑

  

尽管它不能消除指标。

这是带有删除指示符的新样式

<controls:DataGrid>
    <controls:DataGrid.RowGroupHeaderStyles>
        <Style TargetType="controls:DataGridRowGroupHeader">
            <Setter Property="IsTabStop" Value="False"/>
            <Setter Property="IsHitTestVisible" Value="False"/>
            <Setter Property="FontSize" Value="15"/>
            <Setter Property="MinHeight" Value="32"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="controls:DataGridRowGroupHeader">
                        <Grid x:Name="RowGroupHeaderRoot" MinHeight="{TemplateBinding MinHeight}">


                            <Grid.Resources>
                                <ControlTemplate x:Key="ToggleButtonTemplate" TargetType="ToggleButton">
                                    <Grid Background="{TemplateBinding Background}">


                                    </Grid>
                                </ControlTemplate>
                            </Grid.Resources>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>

                            <Rectangle x:Name="IndentSpacer" Grid.Column="1"/>
                            <ToggleButton x:Name="ExpanderButton" Grid.Column="2" Height="12" Width="12" Template="{StaticResource ToggleButtonTemplate}"
                                IsTabStop="False" Margin="12,0" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}"/>

                            <StackPanel Grid.Column="3" Orientation="Horizontal" VerticalAlignment="Center" Margin="12,0">
                                <TextBlock x:Name="PropertyNameElement" Margin="4,0" Visibility="{TemplateBinding PropertyNameVisibility}" Style="{ThemeResource BodyTextBlockStyle}" Foreground="{TemplateBinding Foreground}"/>
                                <TextBlock x:Name="PropertyValueElement" Margin="4,0" Style="{ThemeResource BodyTextBlockStyle}" Foreground="{TemplateBinding Foreground}"/>
                                <TextBlock x:Name="ItemCountElement" Margin="4,0" Visibility="{TemplateBinding ItemCountVisibility}" Style="{ThemeResource BodyTextBlockStyle}" Foreground="{TemplateBinding Foreground}"/>
                            </StackPanel>

                            <Rectangle x:Name="CurrencyVisual" Grid.ColumnSpan="5"
                                StrokeThickness="1" Fill="Transparent"
                                HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsHitTestVisible="False" Opacity="0"/>
                            <Grid x:Name="FocusVisual" Grid.ColumnSpan="5" IsHitTestVisible="False" Opacity="0">
                                <Rectangle  StrokeThickness="2" Fill="Transparent"
                                           HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsHitTestVisible="False"/>
                                <Rectangle  StrokeThickness="1" Fill="Transparent"
                                           HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsHitTestVisible="False" Margin="2"/>
                            </Grid>


                            <Rectangle x:Name="BottomGridLine" Grid.ColumnSpan="5" Height="1" Grid.Row="1"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </controls:DataGrid.RowGroupHeaderStyles>
</controls:DataGrid>
本文链接:https://www.f2er.com/3107908.html

大家都在问