2015-07-20 123 views
0

我有dataGrid樣式的問題,它工作正常,但是在我更改dataGrid樣式後,另一個樣式消失。我把代碼運行的很好,結果的圖片,然後我改變了什麼,改變後我得到了什麼。也許有人知道它如何寫得更好?與dataGrid樣式奮鬥WPF

<Style TargetType="DataGridRow"> 
     <Setter Property="SnapsToDevicePixels" Value="True" /> 
     <Setter Property="BorderThickness" Value="1"/> 
     <Setter Property="BorderBrush" Value="#E6E6E6"/> 
     <Setter Property="ContextMenu" Value="{x:Null}"/> 
     <Style.Triggers> 
      <Trigger Property="AlternationIndex" Value="0"> 
       <Setter Property="Background" Value="#FFFFFF"/> 
      </Trigger> 
      <Trigger Property="AlternationIndex" Value="1"> 
       <Setter Property="Background" Value="#F7F7F7"/> 
      </Trigger> 
      <Trigger Property="IsSelected" 
        Value="True"> 
       <Setter Property="BorderThickness" 
         Value="2"/> 
       <Setter Property="BorderBrush" 
        Value="#FFBA59" /> 
      </Trigger> 
     </Style.Triggers> 

    </Style> 

    <Style TargetType="{x:Type DataGridColumnHeader}"> 
     <Setter Property="BorderThickness" Value="0"/> 
     <Setter Property="BorderBrush" Value="#FFFFFF"/> 
    </Style> 
     <!--Style x:Key="HeaderStyle" TargetType="{x:Type DataGridColumnHeader}"> 
     <Setter Property="Background" Value="#FFFFFF"/> 
     <Setter Property="BorderThickness" Value="0"/> 
     <Setter Property="BorderBrush" Value="#E6E6E6"/> 
     <Setter Property="Height" Value="35"/> 
     <Setter Property="FontFamily" Value="Arial"/> 
     <Setter Property="FontWeight" Value="Bold"/> 
     <Setter Property="FontSize" Value="15"/> 
     <Setter Property="IsEnabled" Value="False"/> 
     <Setter Property="VerticalAlignment" Value="Bottom" /> 
    </Style--> 



    <DataGridTextColumn x:Key="product" Header=" Product" FontFamily="Arial" Width="3*" Binding="{Binding Name}" IsReadOnly="True" 
         FontSize="18" FontWeight="Normal" Foreground="#4D4D4D"> 
     <DataGridTextColumn.ElementStyle> 
      <Style TargetType="TextBlock"> 
       <Setter Property="VerticalAlignment" Value="Center" /> 
       <Setter Property="HorizontalAlignment" Value="Center" /> 
       <Setter Property="Width" Value="700"/> 
      </Style> 
     </DataGridTextColumn.ElementStyle> 
     <DataGridTextColumn.HeaderStyle> 
      <Style TargetType="{x:Type DataGridColumnHeader}"> 

       <Setter Property="Background" Value="#FFFFFF"/> 
       <Setter Property="BorderThickness" Value="0"/> 
       <Setter Property="BorderBrush" Value="#E6E6E6"/> 
       <Setter Property="Height" Value="35"/> 
       <Setter Property="FontFamily" Value="Arial"/> 
       <Setter Property="FontWeight" Value="Bold"/> 
       <Setter Property="FontSize" Value="15"/> 
       <Setter Property="IsEnabled" Value="False"/> 
       <Setter Property="VerticalAlignment" Value="Center"/> 
       <Setter Property="HorizontalContentAlignment" Value="Left"/> 
      </Style> 
     </DataGridTextColumn.HeaderStyle> 
    </DataGridTextColumn> 
    <DataGridTextColumn x:Key="unit price" Header="Unit price, € " FontFamily="Arial" Width="0.5*" Binding="{Binding Age}" IsReadOnly="True" 
         FontSize="18" FontWeight="Normal" Foreground="#4D4D4D"> 
     <DataGridTextColumn.ElementStyle> 
      <Style TargetType="TextBlock"> 
       <Setter Property="VerticalAlignment" Value="Center" /> 
       <Setter Property="HorizontalAlignment" Value="Right"/> 
      </Style> 
     </DataGridTextColumn.ElementStyle> 
     <DataGridTextColumn.HeaderStyle> 
      <Style TargetType="{x:Type DataGridColumnHeader}"> 
       <Setter Property="Background" Value="#FFFFFF"/> 
       <Setter Property="BorderThickness" Value="0"/> 
       <Setter Property="BorderBrush" Value="#E6E6E6"/> 
       <Setter Property="Height" Value="35"/> 
       <Setter Property="FontFamily" Value="Arial"/> 
       <Setter Property="FontWeight" Value="Bold"/> 
       <Setter Property="FontSize" Value="15"/> 
       <Setter Property="IsEnabled" Value="False"/> 
       <Setter Property="VerticalAlignment" Value="Center"/> 
       <Setter Property="HorizontalContentAlignment" Value="Right"/> 
      </Style> 
     </DataGridTextColumn.HeaderStyle> 
    </DataGridTextColumn> 
    <DataGridTextColumn x:Key="quantity" Header="Quantity" FontFamily="Arial" Width="0.7*" Binding="{Binding Country}" IsReadOnly="True" 
         FontSize="18" FontWeight="Normal" Foreground="#4D4D4D"> 
     <DataGridTextColumn.ElementStyle> 
      <Style TargetType="TextBlock"> 
       <Setter Property="VerticalAlignment" Value="Center" /> 
       <Setter Property="HorizontalAlignment" Value="Center"/> 
      </Style> 
     </DataGridTextColumn.ElementStyle> 
     <DataGridTextColumn.HeaderStyle> 
      <Style TargetType="{x:Type DataGridColumnHeader}"> 
       <Setter Property="Background" Value="#FFFFFF"/> 
       <Setter Property="BorderThickness" Value="0"/> 
       <Setter Property="BorderBrush" Value="#E6E6E6"/> 
       <Setter Property="Height" Value="35"/> 
       <Setter Property="FontFamily" Value="Arial"/> 
       <Setter Property="FontWeight" Value="Bold"/> 
       <Setter Property="FontSize" Value="15"/> 
       <Setter Property="IsEnabled" Value="False"/> 
       <Setter Property="VerticalAlignment" Value="Center"/> 
       <Setter Property="HorizontalContentAlignment" Value="Center"/> 
      </Style> 
     </DataGridTextColumn.HeaderStyle> 
    </DataGridTextColumn> 
    <DataGridTextColumn x:Key="price" Header="Price, € " FontFamily="Arial" Width="0.3*" Binding="{Binding adress}" IsReadOnly="True" 
         FontSize="18" FontWeight="Normal" Foreground="#4D4D4D"> 
     <DataGridTextColumn.ElementStyle> 
      <Style TargetType="TextBlock"> 
       <Setter Property="Width" Value="25"/> 
       <Setter Property="VerticalAlignment" Value="Center" /> 
       <Setter Property="HorizontalAlignment" Value="Right"/> 
      </Style> 
     </DataGridTextColumn.ElementStyle> 
     <DataGridTextColumn.HeaderStyle> 
      <Style TargetType="{x:Type DataGridColumnHeader}"> 
       <Setter Property="Background" Value="#FFFFFF"/> 
       <Setter Property="BorderThickness" Value="0"/> 
       <Setter Property="BorderBrush" Value="#E6E6E6"/> 
       <Setter Property="Height" Value="35"/> 
       <Setter Property="FontFamily" Value="Arial"/> 
       <Setter Property="FontWeight" Value="Bold"/> 
       <Setter Property="FontSize" Value="15"/> 
       <Setter Property="IsEnabled" Value="False"/> 
       <Setter Property="VerticalAlignment" Value="Center"/> 
       <Setter Property="HorizontalContentAlignment" Value="Center"/> 
      </Style> 
     </DataGridTextColumn.HeaderStyle> 
    </DataGridTextColumn> 

    <Style TargetType="DataGridCell"> 
     <Setter Property="BorderThickness" Value="0"/> 
    </Style> 
    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FFD65E" /> 


    <Style TargetType="{x:Type DataGrid}"> 
     <Setter Property="Background" Value="#FFFFFF"/> 
     <Setter Property="BorderThickness" Value="1"/> 
     <Setter Property="BorderBrush" Value="#E6E6E6"/> 
    </Style> 
</Window.Resources> 


<Grid> 
    <DataGrid x:Name="lbPersonList" Margin="30,98,362,30" AlternationCount="2" VerticalScrollBarVisibility="Visible" AutoGenerateColumns="False" 
       RowHeight="42" GridLinesVisibility="None" HorizontalGridLinesBrush="#E6E6E6" CanUserAddRows="False" SelectionMode="Single" 
       HeadersVisibility="Column" > 

      <DataGrid.Columns> 
       <StaticResource ResourceKey="product"/> 
       <StaticResource ResourceKey="unit price"/> 
       <StaticResource ResourceKey="quantity"/> 
       <StaticResource ResourceKey="price"/> 
      </DataGrid.Columns> 
     </DataGrid> 


</Grid> 

我只更改的數據網格樣式:

<Style TargetType="{x:Type DataGrid}"> 
     <Setter Property="Background" Value="#FFFFFF"/> 
     <Setter Property="BorderThickness" Value="1"/> 
     <Setter Property="BorderBrush" Value="#E6E6E6"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate> 
        <Border CornerRadius="10" BorderThickness="2" BorderBrush="Black"/> 

       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
+0

讀了'ControlTemplate'只包含一個邊界的定義。所有其他信息缺少如何格式化(位置,樣式,...)「DataGrid」的內容。你想要完成什麼?添加一個圓角的邊框到'數據網格'? – gomi42

+0

是的,我想第一個圖像中的DataGrid是圓角的 – LTU

回答

0
<Setter Property="Background" Value="#FFFFFF"/> 

#FFFFFF表示白色。你正在設置datagrid的背景顏色爲白色,這就是爲什麼你不能在屏幕上看到任何東西。

+0

你有關