簡體   English   中英

WPF DataGrid右“裝訂線”被選中觸發器

[英]Wpf DataGrid Right “Gutter” IsSelected Trigger

在Wpf DataGrid中,每一行都有一個空白區域,該區域會增長以填充剩余空間。 我以為這個區域被更恰當地稱為“裝訂線”,但實際上我不知道適用的術語。 我喜歡這個,但是我注意到了一個問題。 如果單擊空白區域,它似乎無法處理IsSelected上設置的IsSelected觸發器。 但是,將觸發IsMouseOver觸發器。 很奇怪。 這是展示我提到的區域的圖片:

在此處輸入圖片說明

這是Xaml的部分,我認為將需要解決此問題。 如果需要更多,請告訴我,我會發布。

<!--  Style and template for the DataGridRow.  -->
    <Style x:Key="VoidwalkerDataGridRowStyle" TargetType="{x:Type DataGridRow}">
        <Setter Property="SnapsToDevicePixels" Value="true" />
        <Setter Property="Validation.ErrorTemplate" Value="{x:Null}" />
        <Setter Property="ValidationErrorTemplate">
            <Setter.Value>
                <ControlTemplate>
                    <TextBlock
                        Margin="2,0,0,0"
                        VerticalAlignment="Center"
                        Foreground="Red"
                        Text="!" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridRow}">
                    <Border
                        x:Name="DGR_Border"
                        Background="{DynamicResource VoidwalkerContextBrush}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        SnapsToDevicePixels="True">
                        <SelectiveScrollingGrid>
                            <SelectiveScrollingGrid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </SelectiveScrollingGrid.ColumnDefinitions>
                            <SelectiveScrollingGrid.RowDefinitions>
                                <RowDefinition Height="*" />
                                <RowDefinition Height="Auto" />
                            </SelectiveScrollingGrid.RowDefinitions>
                            <DataGridCellsPresenter
                                Grid.Column="1"
                                ItemsPanel="{TemplateBinding ItemsPanel}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            <DataGridDetailsPresenter
                                Grid.Row="1"
                                Grid.Column="1"
                                SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding AreRowDetailsFrozen, ConverterParameter={x:Static SelectiveScrollingOrientation.Vertical}, Converter={x:Static DataGrid.RowDetailsScrollingConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
                                Visibility="{TemplateBinding DetailsVisibility}" />
                            <DataGridRowHeader
                                Grid.Row="0"
                                Grid.RowSpan="2"
                                Grid.Column="0"
                                SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical"
                                Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Row}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />
                        </SelectiveScrollingGrid>

                    </Border>
                    <ControlTemplate.Triggers>
                        <!--
                            Alternation Coloration Triggers
                        -->
                        <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                            <Setter Property="Foreground" Value="{DynamicResource VoidwalkerForegroundBrush}" />
                            <Setter TargetName="DGR_Border" Property="Background" Value="{DynamicResource VoidwalkerContextBrush}" />
                        </Trigger>
                        <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                            <Setter Property="Foreground" Value="{DynamicResource VoidwalkerForegroundBrush}" />
                            <Setter TargetName="DGR_Border" Property="Background" Value="{DynamicResource VoidwalkerControlBrush}" />
                        </Trigger>
                        <!--
                            Is Selected Triggers
                        -->
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="DGR_Border" Property="BorderBrush" Value="{DynamicResource VoidwalkerBorderBrush}" />
                            <Setter TargetName="DGR_Border" Property="Background" Value="{DynamicResource VoidwalkerBorderBrush}" />
                        </Trigger>

                        <!--
                            Is Mouse Over Triggers
                        -->
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="DGR_Border" Property="BorderBrush" Value="{DynamicResource VoidwalkerBorderBrush}" />
                            <Setter TargetName="DGR_Border" Property="Background" Value="{DynamicResource VoidwalkerBorderBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

只是為了進一步澄清我的問題:

當我單擊圖片中的“ IsSelected線”區域時, IsSelected觸發我的IsSelected觸發器。 如果單擊左側的任何單元格,則將選擇該行。 奇怪的是,將鼠標懸停在裝訂線區域上時,我的另一個IsMouseOver觸發器仍然被觸發。 有沒有一種方法可以模擬IsSelected的裝訂線區域上的IsSelected行為?

只能選擇實際的單元格。 您只需在DataGrid添加另一個空白列,就可以輕松地使“裝訂線”成為可選項:

<DataGrid.Columns>
    ...
    <DataGridTemplateColumn Width="*" />
</DataGrid.Columns>

或通過將其最后一個Width設置為*來水平拉伸現有列。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM