wpf datagrid樣式
https://www.cnblogs.com/xiaogangqq123/archive/2012/05/07/2487166.html
<Window.Resources>
<local:ImagePathConverter x:Key="ImagePathConverter" />
<Style TargetType="DataGrid">
<!--網格線顏色-->
<Setter Property="CanUserResizeColumns" Value="false" />
<Setter Property="Background" Value="#E6DBBB" />
<Setter Property="BorderBrush" Value="#d6c79b" />
<Setter Property="HorizontalGridLinesBrush">
<Setter.Value>
<SolidColorBrush Color="#d6c79b" />
</Setter.Value>
</Setter>
<Setter Property="VerticalGridLinesBrush">
<Setter.Value>
<SolidColorBrush Color="#d6c79b" />
</Setter.Value>
</Setter>
</Style>
<!--標題欄樣式-->
<Style TargetType="DataGridColumnHeader">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="MinWidth" Value="0" />
<Setter Property="MinHeight" Value="28" />
<Setter Property="Foreground" Value="#323433" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DataGridColumnHeader">
<Border x:Name="BackgroundBorder" BorderThickness="0,1,0,1"
BorderBrush="#e6dbba"
Width="Auto">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ContentPresenter Margin="0,0,0,0" VerticalAlignment="Center"
HorizontalAlignment="Center" />
<Path x:Name="SortArrow" Visibility="Collapsed" Data="M0,0 L1,0 0.5,1 z" Stretch="Fill"
Grid.Column="0" Width="8" Height="6" Fill="White" Margin="0,0,50,0"
VerticalAlignment="Center" RenderTransformOrigin="1,1" />
<Rectangle Width="1" Fill="#d6c79b" HorizontalAlignment="Right" Grid.ColumnSpan="1" />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Height" Value="25" />
</Style>
<!--行樣式觸發-->
<!--背景色改變必須先設定cellStyle 因為cellStyle會覆蓋rowStyle樣式-->
<Style TargetType="DataGridRow">
<Setter Property="Background" Value="#F2F2F2" />
<Setter Property="Height" Value="25" />
<Setter Property="Foreground" Value="Black" />
<Style.Triggers>
<!--隔行換色-->
<Trigger Property="AlternationIndex" Value="0">
<Setter Property="Background" Value="#e7e7e7" />
</Trigger>
<Trigger Property="AlternationIndex" Value="1">
<Setter Property="Background" Value="#f2f2f2" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="LightGray" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="Black" />
</Trigger>
</Style.Triggers>
</Style>
<!--單元格樣式觸發-->
<Style TargetType="DataGridCell">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DataGridCell">
<TextBlock TextAlignment="Center" VerticalAlignment="Top">
<ContentPresenter />
</TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="White" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Foreground" Value="Black" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<DataGrid x:Name="gridProducts" Margin="5" AutoGenerateColumns="False" RowHeight="100"
LoadingRow="gridProducts_LoadingRow"
FrozenColumnCount="1"
VerticalAlignment="Top"
IsReadOnly="True"
CanUserResizeColumns="False" CanUserResizeRows="False" SelectionMode="Single"
CanUserReorderColumns="False" AlternationCount="2" RowHeaderWidth="0" CanUserAddRows="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Product" Width="175" Binding="{Binding ModelName}" />
<DataGridTextColumn Header="Price" Binding="{Binding UnitCost, StringFormat={}{0:C}}" />
<DataGridTextColumn Header="Model Number" Binding="{Binding ModelNumber}" />
<DataGridTextColumn Width="400" Binding="{Binding Description}" Header="Description">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn IsReadOnly="True" Header="Category" Binding="{Binding CategoryName}" />
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Stretch="None"
Source="{Binding ProductImagePath, Converter={StaticResource ImagePathConverter}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
相關文章
- WPF datagrid mvvm multi select via customize datagridMVVM
- WPF DataGrid ItemsSource StaticResource
- WPF datagrid scrollintoview in ViewModel of MVVMViewMVVM
- WPF Datagrid display via DataGridTemplateColumn
- WPF datagrid show ImageBrush via DataGridTemplateColumn
- WPF Slider樣式IDE
- WPF SelectedItemCollection convert to IList and List, such as Datagrid SelectedItems
- WPF datagrid datagridtemplatecolumn DataGridTemplateColumn.CellEditingTemplate DataGridComboBoxColumn
- WPF datagrid scrolldown and change the marked the location in canvasCanvas
- WPF custom control contains datagrid,listbox,imageAI
- WPF --- 如何以Binding方式隱藏DataGrid列
- WPF中Datagrid控制元件新增行號控制元件
- WPF --- 如何重寫WPF原生控制元件樣式控制元件
- WPF datagrid implement multi select via behavior selectionchanged event in MVVMMVVM
- WPF DataGrid ContextMenu CommandParameter Relative x:Type ContextMenu ,Path=PlacementTargetContext
- WPF隨筆收錄-DataGrid固定右側列
- WPF/C#:在DataGrid中顯示選擇框C#
- WPF DataGrid開箱即用支援全部勾選的DataGridCheckBoxColumn
- WPF入門教程系列二十四——DataGrid使用示例(1)
- WPF DataGrid實現單擊單元格直接編輯
- WPF基礎—佈局,樣式,觸發器觸發器
- WPF 怎麼把checkbox改成開關樣式
- WPF滑塊控制元件(Slider)的自定義樣式控制元件IDE
- WPF的DataGrid使用AutoGenerateColumns自動生成列的時候,控制列的寬度
- WPF登入介面樣例
- 【原創】WPF TreeView帶連線線樣式的優化(WinFrom風格)View優化
- WPF—DataGrid設定列的百分比寬度 & 列值顯示格式化
- 【WPF】 問題總結-RaidButton修改樣式模板後作用區域的變化AI
- easyui datagrid 禁止選中行UI
- 常用CSS樣式2:其它樣式CSS
- 常用CSS樣式1:文字樣式CSS
- 繫結class樣式和style樣式
- 1.5 常用CSS樣式1:文字樣式CSS
- 1.6 常用CSS樣式2:其它樣式CSS
- WPF 模擬UWP原生視窗樣式——亞克力|雲母材質、自定義標題欄樣式、原生DWM動畫 (附我封裝好的類)動畫封裝
- datagrid 頁面新增合計值
- HTML 樣式HTML
- css樣式CSS