2017-12-08 8 views
0

Wpf DataGridでは、各行は、残りの領域を埋めるために拡大する空白領域を持っています。私はこの地域をより適切に「ガッター」と呼んでいると想像していますが、実際には適切な用語を知らないのです。私はこれが好きですが、私はそれに問題があることに気付きました。空白領域をクリックすると、行に設定したIsSelectedトリガーを処理していないように見えます。ただし、IsMouseOverトリガーが発生します。非常に奇妙な。ここで私が言及しているエリアを実証絵です:Wpf DataGrid右 "ガター" IsSelectedトリガー

enter image description here

そして、ここでは、私はこの問題を解決するために必要なことになると思う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トリガが発生しません。左側のセルをクリックすると、その行が選択されます。奇妙なことは、私の他のIsMouseOverトリガーは、ガターエリアにマウスをかざすときにまだ発射されているということです。それがある行の溝エリアでIsSelectedの動作をエミュレートできる方法はありますか?

答えて

1

選択できるのは実際のセルだけです。あなたは簡単に単にあなたのDataGridに別の空白の列を追加することによって、「ガター」選択を行うことができます。

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

それとも*にそのWidthを設定することにより、水平方向の最後の既存の列のストレッチを行います。