2017-06-28 1 views
0

Je travaille sur un projet VSIX (Visual Studio Extension). Il contient un DataGrid WPF. Je dois définir une couleur de surbrillance de ligne DataGrid personnalisée, lorsque DataGrid devient inactif (focus perdu), basé sur le thème Visual Studio.Comment définir la couleur de ligne inactive de WPF DataGrid en fonction du thème Visual Studio

Bien que de nombreux types similaires de Q & As soient détectés via le dépassement de pile, je suis incapable de trouver une solution basée sur le thème Visual Studio.

Je suis tombé sur le morceau de code suivant (style). Cependant, il ne couvre pas mes besoins, S'il vous plaît aider à résoudre ce problème.

<DataGrid.CellStyle> 
      <Style TargetType="{x:Type DataGridCell}"> 
       <Style.Triggers> 
        <Trigger Property="IsSelected" Value="true"> 
         <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" /> 
         <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" /> 
         <Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" /> 
        </Trigger> 
        <MultiDataTrigger> 
         <MultiDataTrigger.Conditions> 
          <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsSelected}" Value="True" /> 
          <Condition Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}, Path=IsKeyboardFocusWithin}" Value="False" /> 
         </MultiDataTrigger.Conditions> 

         <MultiDataTrigger.Setters> 

          <!--Following Background color has to be changed based on VS theme--> 
          <Setter Property="Background" Value="DarkGray" /> 

          <Setter Property="Foreground" Value="{DynamicResource VsBrush.WindowText}" /> 

          <!--This BorderBrush color has to be changed based on VS theme--> 
          <Setter Property="BorderBrush" Value="DarkGray"/> 
         </MultiDataTrigger.Setters> 
        </MultiDataTrigger> 
       </Style.Triggers> 
      </Style> 
     </DataGrid.CellStyle> 

Merci

Répondre

0

vous pouvez essayer d'utiliser VsBrushes ou EnvironmentColors pour y parvenir. comme ceci:

<UserControl x:Class="TWToolbar.TestToolWindowControl" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:vsShell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.14.0" 
      xmlns:vsUI="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.14.0" 

      mc:Ignorable="d" 
      d:DesignHeight="400" d:DesignWidth="500" 
      Name="MyToolWindow"> 
    <Grid> 
     <StackPanel Orientation="Vertical"> 
      <Button Content="Click me!" Click="button1_Click" Width="120" Height="20" Name="button1"/> 
      <DataGrid Name="dgUsers" AutoGenerateColumns="False"> 
      <DataGrid.CellStyle> 
       <Style TargetType="{x:Type DataGridCell}"> 
        <Style.Triggers> 
         <Trigger Property="IsSelected" Value="true"> 
          <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" /> 
          <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" /> 
          <Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" /> 
         </Trigger> 
         <MultiDataTrigger> 
          <MultiDataTrigger.Conditions> 
           <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsSelected}" Value="True" /> 
           <Condition Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}, Path=IsKeyboardFocusWithin}" Value="False" /> 
          </MultiDataTrigger.Conditions> 
          <MultiDataTrigger.Setters> 
           <!--Following Background color has to be changed based on VS theme WindowText--> 
           <Setter Property="Background" Value="DarkGray" /> 
           <Setter Property="Foreground" Value="{DynamicResource {x:Static vsShell:VsBrushes.AccentBorderKey}}"/> 
           <!--<Setter Property="Foreground" Value="{DynamicResource {x:Static vsUI:EnvironmentColors.AccentBorderBrushKey}}"/>--> 
           <!--This BorderBrush color has to be changed based on VS theme--> 
           <Setter Property="BorderBrush" Value="DarkGray"/> 
          </MultiDataTrigger.Setters> 
         </MultiDataTrigger> 
        </Style.Triggers> 
       </Style> 
      </DataGrid.CellStyle> 
       <DataGrid.Columns> 
        <DataGridTextColumn Header="Name" Binding="{Binding Name}" /> 
        <DataGridTextColumn Header="Birthday" Binding="{Binding Birthday}" /> 
       </DataGrid.Columns> 
      </DataGrid> 
     </StackPanel> 
    </Grid> 
</UserControl> 

enter image description here

+0

La question entendre est basée sur la couleur de VsBrush Rawbackground, je dois appliquer/définir une couleur inactive en surbrillance de la ligne. En d'autres termes Si (Vs Thème = Foncé) Puis Inactif Rowbackground = Rouge, Si (Vs Thème = Léger) Puis Inactif Rowbackground = Vert Merci –