微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决带有扩展器的 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.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?