带有扩展器的 WPF Datagrid RowheaderTemplate => 使 RowDetailHeader 可点击

问题描述

在我的 UserControl 中,我在 RowHeaderTemplate 中使用了带有扩展器的数据网格。 这也很好用,数据显示正确。

我已经在这里找到了一个示例来更改扩展器标题的样式(“+”和“-”,带有鼠标悬停显示)。

但是,我必须用鼠标非常精确地点击小“+”或“-”才能操作扩展器。

我需要进行哪些更改才能使整个扩展单元响应扩展数据网格行?

链接是 2 个屏幕截图,可以阐明我的意思。

Tooglebutton does not respond

Tooglebutton respond

<DataGrid.RowHeaderTemplate>
  <DataTemplate>
    <Expander Expanded="_expander_ChangeExpand" Collapsed="_expander_ChangeExpand" Style="{StaticResource PlusMinusExpander}"/>
  </DataTemplate>
</DataGrid.RowHeaderTemplate>
<Style x:Key="ExpanderHeaderFocusVisual">
    <Setter Property="Control.Template">
        <Setter.Value>
            <ControlTemplate>
                <Border>
                    <Rectangle Margin="0" SnapsToDevicePixels="true" stroke="Black" strokeThickness="1" strokeDashArray="1 2"/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
<Style x:Key="ExpanderDownHeaderStyle" targettype="{x:Type ToggleButton}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate targettype="{x:Type ToggleButton}">
                <Border Padding="{TemplateBinding Padding}">
                    <Grid Background="Transparent" SnapsToDevicePixels="True">
                        <Grid.ColumnDeFinitions>
                            <ColumnDeFinition Width="15"/>
                            <ColumnDeFinition Width="*"/>
                        </Grid.ColumnDeFinitions>
                        <Image x:Name="arrow" Source="{Binding Source,Source={StaticResource closed}}"  Width="12"/>
                        <ContentPresenter Grid.Column="1" HorizontalAlignment="Stretch" Margin="4,0" RecognizesAccessKey="True" 
                                          SnapsToDevicePixels="True" VerticalAlignment="Stretch"/>
                    </Grid>
                </Border>

                <ControlTemplate.Triggers>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsChecked" Value="true" />
                            <Condition Property="IsMouSEOver" Value="false" />
                        </MultiTrigger.Conditions>
                        <Setter Property="Source" TargetName="arrow" Value="{Binding Source,Source={StaticResource open}}"/>
                    </MultiTrigger>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsChecked" Value="true" />
                            <Condition Property="IsMouSEOver" Value="true" />
                        </MultiTrigger.Conditions>
                        <Setter Property="Source" TargetName="arrow" Value="{Binding Source,Source={StaticResource open_plasticwrap}}"/>
                    </MultiTrigger>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsChecked" Value="false" />
                            <Condition Property="IsMouSEOver" Value="true" />
                        </MultiTrigger.Conditions>
                        <Setter Property="Source" TargetName="arrow" Value="{Binding Source,Source={StaticResource closed_plasticwrap}}"/>
                    </MultiTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
<Style x:Key="PlusMinusExpander" targettype="{x:Type Expander}">
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    <Setter Property="VerticalContentAlignment" Value="Stretch"/>
    <Setter Property="BorderBrush" Value="Transparent"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate targettype="{x:Type Expander}">
                <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"
                        CornerRadius="3" SnapsToDevicePixels="true">
                    <DockPanel>
                        <ToggleButton x:Name="HeaderSite" DockPanel.Dock="Top" ContentTemplate="{TemplateBinding HeaderTemplate}" ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}" 
                                      Content="{TemplateBinding Header}" Foreground="{TemplateBinding Foreground}" 
                                      FontWeight="{TemplateBinding FontWeight}" FocusVisualStyle="{StaticResource ExpanderHeaderFocusVisual}" 
                                      FontStyle="{TemplateBinding FontStyle}" FontStretch="{TemplateBinding FontStretch}" FontSize="{TemplateBinding FontSize}" 
                                      FontFamily="{TemplateBinding FontFamily}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                      IsChecked="{Binding IsExpanded,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}" Margin="1" 
                                      MinWidth="0" MinHeight="0" Padding="{TemplateBinding Padding}" Style="{StaticResource ExpanderDownHeaderStyle}" 
                                      VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        <ContentPresenter x:Name="ExpandSite" DockPanel.Dock="Bottom" Grid.Column="1" Focusable="false" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                          Margin="{TemplateBinding Padding}" Visibility="Collapsed" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                    </DockPanel>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsExpanded" Value="true">
                        <Setter Property="Visibility" TargetName="ExpandSite" Value="Visible"/>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...