modified datagrid style

RowHeight, ColumnHeaderHeight, ShowSelectAllButton
This commit is contained in:
NaBian 2021-08-03 22:28:37 +08:00
parent 1938e74d02
commit b7e08aec23
8 changed files with 132 additions and 17 deletions

View File

@ -92,13 +92,13 @@
</MultiTrigger> </MultiTrigger>
</Style.Triggers> </Style.Triggers>
</Style> </Style>
<Style x:Key="DataGridRowStyle" TargetType="DataGridRow"> <Style x:Key="DataGridRowStyle" TargetType="DataGridRow">
<Setter Property="Background" Value="{DynamicResource RegionBrush}"/> <Setter Property="Background" Value="{DynamicResource RegionBrush}"/>
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"/> <Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"/>
<Setter Property="SnapsToDevicePixels" Value="true"/> <Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="Margin" Value="0,0,0,4"/> <Setter Property="Margin" Value="0,0,0,4"/>
<Setter Property="Padding" Value="0,6"/> <Setter Property="Padding" Value="0,6"/>
<Setter Property="MinHeight" Value="44"/>
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/> <Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
<Setter Property="ValidationErrorTemplate"> <Setter Property="ValidationErrorTemplate">
<Setter.Value> <Setter.Value>
@ -145,6 +145,7 @@
</MultiTrigger> </MultiTrigger>
</Style.Triggers> </Style.Triggers>
</Style> </Style>
<Style x:Key="ColumnHeaderGripperStyle" TargetType="Thumb"> <Style x:Key="ColumnHeaderGripperStyle" TargetType="Thumb">
<Setter Property="Width" Value="8"/> <Setter Property="Width" Value="8"/>
<Setter Property="Background" Value="Transparent"/> <Setter Property="Background" Value="Transparent"/>
@ -157,11 +158,11 @@
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style x:Key="DataGridColumnHeaderStyle" TargetType="DataGridColumnHeader"> <Style x:Key="DataGridColumnHeaderStyle" TargetType="DataGridColumnHeader">
<Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"/> <Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"/>
<Setter Property="Padding" Value="12,6,12,12"/> <Setter Property="Padding" Value="12,0"/>
<Setter Property="MinHeight" Value="44"/>
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="DataGridColumnHeader"> <ControlTemplate TargetType="DataGridColumnHeader">
@ -203,6 +204,7 @@
</Trigger> </Trigger>
</Style.Triggers> </Style.Triggers>
</Style> </Style>
<Style x:Key="DataGridRowHeaderStyle" TargetType="DataGridRowHeader"> <Style x:Key="DataGridRowHeaderStyle" TargetType="DataGridRowHeader">
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
@ -220,6 +222,7 @@
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style x:Key="TextBlockComboBoxStyle" TargetType="ComboBox"> <Style x:Key="TextBlockComboBoxStyle" TargetType="ComboBox">
<Setter Property="Focusable" Value="True"/> <Setter Property="Focusable" Value="True"/>
<Setter Property="Template"> <Setter Property="Template">
@ -230,9 +233,11 @@
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style x:Key="DataGridTextColumnStyle" TargetType="TextBlock"> <Style x:Key="DataGridTextColumnStyle" TargetType="TextBlock">
<Setter Property="TextTrimming" Value="CharacterEllipsis"/> <Setter Property="TextTrimming" Value="CharacterEllipsis"/>
</Style> </Style>
<Style TargetType="DataGrid"> <Style TargetType="DataGrid">
<Setter Property="Background" Value="{DynamicResource SecondaryRegionBrush}"/> <Setter Property="Background" Value="{DynamicResource SecondaryRegionBrush}"/>
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
@ -253,6 +258,8 @@
<Setter Property="CellStyle" Value="{StaticResource DataGridCellStyle}"/> <Setter Property="CellStyle" Value="{StaticResource DataGridCellStyle}"/>
<Setter Property="Padding" Value="6"/> <Setter Property="Padding" Value="6"/>
<Setter Property="ColumnWidth" Value="*"/> <Setter Property="ColumnWidth" Value="*"/>
<Setter Property="RowHeight" Value="44"/>
<Setter Property="ColumnHeaderHeight" Value="44"/>
<Setter Property="hc:DataGridAttach.TextColumnStyle" Value="{StaticResource DataGridTextColumnStyle}"/> <Setter Property="hc:DataGridAttach.TextColumnStyle" Value="{StaticResource DataGridTextColumnStyle}"/>
<Setter Property="hc:DataGridAttach.EditingTextColumnStyle" Value="{StaticResource TextBoxBaseStyle}"/> <Setter Property="hc:DataGridAttach.EditingTextColumnStyle" Value="{StaticResource TextBoxBaseStyle}"/>
<Setter Property="hc:DataGridAttach.ComboBoxColumnStyle" Value="{StaticResource TextBlockComboBoxStyle}"/> <Setter Property="hc:DataGridAttach.ComboBoxColumnStyle" Value="{StaticResource TextBlockComboBoxStyle}"/>
@ -295,7 +302,14 @@
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Button Command="{x:Static DataGrid.SelectAllCommand}" Margin="0,0,0,6" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.All}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType=DataGrid}}" Width="{Binding CellsPanelHorizontalOffset, RelativeSource={RelativeSource AncestorType=DataGrid},Converter={StaticResource DoubleMinConverter}}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource AllGeometry}" Foreground="{DynamicResource PrimaryBrush}"/> <Button Command="{x:Static DataGrid.SelectAllCommand}" Width="{Binding CellsPanelHorizontalOffset, RelativeSource={RelativeSource AncestorType=DataGrid},Converter={StaticResource DoubleMinConverter}}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource AllGeometry}" Foreground="{DynamicResource PrimaryBrush}">
<Button.Visibility>
<MultiBinding Converter="{StaticResource DataGridSelectAllButtonVisibilityConverter}">
<Binding Path="HeadersVisibility" RelativeSource="{RelativeSource AncestorType=DataGrid}"/>
<Binding Path="(hc:DataGridAttach.ShowSelectAllButton)" RelativeSource="{RelativeSource AncestorType=DataGrid}"/>
</MultiBinding>
</Button.Visibility>
</Button>
<DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter" Grid.ColumnSpan="2" Grid.Row="0" Grid.Column="1" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Column}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType=DataGrid}}"/> <DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter" Grid.ColumnSpan="2" Grid.Row="0" Grid.Column="1" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Column}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType=DataGrid}}"/>
<hc:ToggleBlock IsChecked="{Binding HasItems,RelativeSource={RelativeSource AncestorType=DataGrid},Mode=OneWay}" Grid.ColumnSpan="3" Grid.Column="0" Grid.Row="1" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"> <hc:ToggleBlock IsChecked="{Binding HasItems,RelativeSource={RelativeSource AncestorType=DataGrid},Mode=OneWay}" Grid.ColumnSpan="3" Grid.Column="0" Grid.Row="1" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
<hc:ToggleBlock.CheckedContent> <hc:ToggleBlock.CheckedContent>

View File

@ -31,6 +31,7 @@
<converter:Double2GridLengthConverter x:Key="Double2GridLengthConverter" /> <converter:Double2GridLengthConverter x:Key="Double2GridLengthConverter" />
<converter:DoubleMinConverter x:Key="DoubleMinConverter" /> <converter:DoubleMinConverter x:Key="DoubleMinConverter" />
<converter:Object2StringConverter x:Key="Object2StringConverter" /> <converter:Object2StringConverter x:Key="Object2StringConverter" />
<converter:DataGridSelectAllButtonVisibilityConverter x:Key="DataGridSelectAllButtonVisibilityConverter" />
<Color x:Key="EffectShadowColor">#88000000</Color> <Color x:Key="EffectShadowColor">#88000000</Color>
<system:Double x:Key="LargeFontSize">24</system:Double> <system:Double x:Key="LargeFontSize">24</system:Double>
<system:Double x:Key="HeadFontSize">20</system:Double> <system:Double x:Key="HeadFontSize">20</system:Double>
@ -11626,7 +11627,6 @@
<Setter Property="SnapsToDevicePixels" Value="true" /> <Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="Margin" Value="0,0,0,4" /> <Setter Property="Margin" Value="0,0,0,4" />
<Setter Property="Padding" Value="0,6" /> <Setter Property="Padding" Value="0,6" />
<Setter Property="MinHeight" Value="44" />
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}" /> <Setter Property="Validation.ErrorTemplate" Value="{x:Null}" />
<Setter Property="ValidationErrorTemplate"> <Setter Property="ValidationErrorTemplate">
<Setter.Value> <Setter.Value>
@ -11676,8 +11676,7 @@
<Style x:Key="DataGridColumnHeaderStyle" TargetType="DataGridColumnHeader"> <Style x:Key="DataGridColumnHeaderStyle" TargetType="DataGridColumnHeader">
<Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}" /> <Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}" />
<Setter Property="Padding" Value="12,6,12,12" /> <Setter Property="Padding" Value="12,0" />
<Setter Property="MinHeight" Value="44" />
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="DataGridColumnHeader"> <ControlTemplate TargetType="DataGridColumnHeader">
@ -11756,6 +11755,8 @@
<Setter Property="CellStyle" Value="{StaticResource DataGridCellStyle}" /> <Setter Property="CellStyle" Value="{StaticResource DataGridCellStyle}" />
<Setter Property="Padding" Value="6" /> <Setter Property="Padding" Value="6" />
<Setter Property="ColumnWidth" Value="*" /> <Setter Property="ColumnWidth" Value="*" />
<Setter Property="RowHeight" Value="44" />
<Setter Property="ColumnHeaderHeight" Value="44" />
<Setter Property="hc:DataGridAttach.TextColumnStyle" Value="{StaticResource DataGridTextColumnStyle}" /> <Setter Property="hc:DataGridAttach.TextColumnStyle" Value="{StaticResource DataGridTextColumnStyle}" />
<Setter Property="hc:DataGridAttach.EditingTextColumnStyle" Value="{StaticResource TextBoxBaseStyle}" /> <Setter Property="hc:DataGridAttach.EditingTextColumnStyle" Value="{StaticResource TextBoxBaseStyle}" />
<Setter Property="hc:DataGridAttach.ComboBoxColumnStyle" Value="{StaticResource TextBlockComboBoxStyle}" /> <Setter Property="hc:DataGridAttach.ComboBoxColumnStyle" Value="{StaticResource TextBlockComboBoxStyle}" />
@ -11798,7 +11799,14 @@
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Button Command="{x:Static DataGrid.SelectAllCommand}" Margin="0,0,0,6" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.All}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType=DataGrid}}" Width="{Binding CellsPanelHorizontalOffset, RelativeSource={RelativeSource AncestorType=DataGrid},Converter={StaticResource DoubleMinConverter}}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource AllGeometry}" Foreground="{DynamicResource PrimaryBrush}" /> <Button Command="{x:Static DataGrid.SelectAllCommand}" Width="{Binding CellsPanelHorizontalOffset, RelativeSource={RelativeSource AncestorType=DataGrid},Converter={StaticResource DoubleMinConverter}}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource AllGeometry}" Foreground="{DynamicResource PrimaryBrush}">
<Button.Visibility>
<MultiBinding Converter="{StaticResource DataGridSelectAllButtonVisibilityConverter}">
<Binding Path="HeadersVisibility" RelativeSource="{RelativeSource AncestorType=DataGrid}" />
<Binding Path="(hc:DataGridAttach.ShowSelectAllButton)" RelativeSource="{RelativeSource AncestorType=DataGrid}" />
</MultiBinding>
</Button.Visibility>
</Button>
<DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter" Grid.ColumnSpan="2" Grid.Row="0" Grid.Column="1" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Column}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType=DataGrid}}" /> <DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter" Grid.ColumnSpan="2" Grid.Row="0" Grid.Column="1" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Column}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType=DataGrid}}" />
<hc:ToggleBlock IsChecked="{Binding HasItems,RelativeSource={RelativeSource AncestorType=DataGrid},Mode=OneWay}" Grid.ColumnSpan="3" Grid.Column="0" Grid.Row="1" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"> <hc:ToggleBlock IsChecked="{Binding HasItems,RelativeSource={RelativeSource AncestorType=DataGrid},Mode=OneWay}" Grid.ColumnSpan="3" Grid.Column="0" Grid.Row="1" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
<hc:ToggleBlock.CheckedContent> <hc:ToggleBlock.CheckedContent>

View File

@ -336,5 +336,14 @@ namespace HandyControl.Controls
public static bool GetCanUnselectAllWithBlankArea(DependencyObject element) public static bool GetCanUnselectAllWithBlankArea(DependencyObject element)
=> (bool) element.GetValue(CanUnselectAllWithBlankAreaProperty); => (bool) element.GetValue(CanUnselectAllWithBlankAreaProperty);
public static readonly DependencyProperty ShowSelectAllButtonProperty = DependencyProperty.RegisterAttached(
"ShowSelectAllButton", typeof(bool), typeof(DataGridAttach), new PropertyMetadata(ValueBoxes.TrueBox));
public static void SetShowSelectAllButton(DependencyObject element, bool value)
=> element.SetValue(ShowSelectAllButtonProperty, value);
public static bool GetShowSelectAllButton(DependencyObject element)
=> (bool) element.GetValue(ShowSelectAllButtonProperty);
} }
} }

View File

@ -136,6 +136,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\BorderCircularClipConverter.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\BorderCircularClipConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\ColLayoutConverter.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\ColLayoutConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\CornerRadiusSplitConverter.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\CornerRadiusSplitConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\DataGridSelectAllButtonVisibilityConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\Double2GridLengthConverter.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\Double2GridLengthConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\DoubleMinConverter.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\DoubleMinConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\Number2PercentageConverter.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\Number2PercentageConverter.cs" />

View File

@ -27,4 +27,5 @@
<converter:Double2GridLengthConverter x:Key="Double2GridLengthConverter"/> <converter:Double2GridLengthConverter x:Key="Double2GridLengthConverter"/>
<converter:DoubleMinConverter x:Key="DoubleMinConverter"/> <converter:DoubleMinConverter x:Key="DoubleMinConverter"/>
<converter:Object2StringConverter x:Key="Object2StringConverter"/> <converter:Object2StringConverter x:Key="Object2StringConverter"/>
</ResourceDictionary> <converter:DataGridSelectAllButtonVisibilityConverter x:Key="DataGridSelectAllButtonVisibilityConverter"/>
</ResourceDictionary>

View File

@ -91,13 +91,13 @@
</MultiTrigger> </MultiTrigger>
</Style.Triggers> </Style.Triggers>
</Style> </Style>
<Style x:Key="DataGridRowStyle" TargetType="DataGridRow"> <Style x:Key="DataGridRowStyle" TargetType="DataGridRow">
<Setter Property="Background" Value="{DynamicResource RegionBrush}"/> <Setter Property="Background" Value="{DynamicResource RegionBrush}"/>
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"/> <Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"/>
<Setter Property="SnapsToDevicePixels" Value="true"/> <Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="Margin" Value="0,0,0,4"/> <Setter Property="Margin" Value="0,0,0,4"/>
<Setter Property="Padding" Value="0,6"/> <Setter Property="Padding" Value="0,6"/>
<Setter Property="MinHeight" Value="44"/>
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/> <Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
<Setter Property="ValidationErrorTemplate"> <Setter Property="ValidationErrorTemplate">
<Setter.Value> <Setter.Value>
@ -144,6 +144,7 @@
</MultiTrigger> </MultiTrigger>
</Style.Triggers> </Style.Triggers>
</Style> </Style>
<Style x:Key="ColumnHeaderGripperStyle" TargetType="Thumb"> <Style x:Key="ColumnHeaderGripperStyle" TargetType="Thumb">
<Setter Property="Width" Value="8"/> <Setter Property="Width" Value="8"/>
<Setter Property="Background" Value="Transparent"/> <Setter Property="Background" Value="Transparent"/>
@ -156,11 +157,11 @@
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style x:Key="DataGridColumnHeaderStyle" TargetType="DataGridColumnHeader"> <Style x:Key="DataGridColumnHeaderStyle" TargetType="DataGridColumnHeader">
<Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"/> <Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"/>
<Setter Property="Padding" Value="12,6,12,12"/> <Setter Property="Padding" Value="12,0"/>
<Setter Property="MinHeight" Value="44"/>
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="DataGridColumnHeader"> <ControlTemplate TargetType="DataGridColumnHeader">
@ -202,6 +203,7 @@
</Trigger> </Trigger>
</Style.Triggers> </Style.Triggers>
</Style> </Style>
<Style x:Key="DataGridRowHeaderStyle" TargetType="DataGridRowHeader"> <Style x:Key="DataGridRowHeaderStyle" TargetType="DataGridRowHeader">
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
@ -219,6 +221,7 @@
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style x:Key="TextBlockComboBoxStyle" TargetType="ComboBox"> <Style x:Key="TextBlockComboBoxStyle" TargetType="ComboBox">
<Setter Property="Focusable" Value="True"/> <Setter Property="Focusable" Value="True"/>
<Setter Property="Template"> <Setter Property="Template">
@ -229,9 +232,11 @@
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style x:Key="DataGridTextColumnStyle" TargetType="TextBlock"> <Style x:Key="DataGridTextColumnStyle" TargetType="TextBlock">
<Setter Property="TextTrimming" Value="CharacterEllipsis"/> <Setter Property="TextTrimming" Value="CharacterEllipsis"/>
</Style> </Style>
<Style TargetType="DataGrid"> <Style TargetType="DataGrid">
<Setter Property="Background" Value="{DynamicResource SecondaryRegionBrush}"/> <Setter Property="Background" Value="{DynamicResource SecondaryRegionBrush}"/>
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
@ -252,6 +257,8 @@
<Setter Property="CellStyle" Value="{StaticResource DataGridCellStyle}"/> <Setter Property="CellStyle" Value="{StaticResource DataGridCellStyle}"/>
<Setter Property="Padding" Value="6"/> <Setter Property="Padding" Value="6"/>
<Setter Property="ColumnWidth" Value="*"/> <Setter Property="ColumnWidth" Value="*"/>
<Setter Property="RowHeight" Value="44"/>
<Setter Property="ColumnHeaderHeight" Value="44"/>
<Setter Property="hc:DataGridAttach.TextColumnStyle" Value="{StaticResource DataGridTextColumnStyle}"/> <Setter Property="hc:DataGridAttach.TextColumnStyle" Value="{StaticResource DataGridTextColumnStyle}"/>
<Setter Property="hc:DataGridAttach.EditingTextColumnStyle" Value="{StaticResource TextBoxBaseStyle}"/> <Setter Property="hc:DataGridAttach.EditingTextColumnStyle" Value="{StaticResource TextBoxBaseStyle}"/>
<Setter Property="hc:DataGridAttach.ComboBoxColumnStyle" Value="{StaticResource TextBlockComboBoxStyle}"/> <Setter Property="hc:DataGridAttach.ComboBoxColumnStyle" Value="{StaticResource TextBlockComboBoxStyle}"/>
@ -294,7 +301,14 @@
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Button Command="{x:Static DataGrid.SelectAllCommand}" Margin="0,0,0,6" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.All}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType=DataGrid}}" Width="{Binding CellsPanelHorizontalOffset, RelativeSource={RelativeSource AncestorType=DataGrid},Converter={StaticResource DoubleMinConverter}}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource AllGeometry}" Foreground="{DynamicResource PrimaryBrush}"/> <Button Command="{x:Static DataGrid.SelectAllCommand}" Width="{Binding CellsPanelHorizontalOffset, RelativeSource={RelativeSource AncestorType=DataGrid},Converter={StaticResource DoubleMinConverter}}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource AllGeometry}" Foreground="{DynamicResource PrimaryBrush}">
<Button.Visibility>
<MultiBinding Converter="{StaticResource DataGridSelectAllButtonVisibilityConverter}">
<Binding Path="HeadersVisibility" RelativeSource="{RelativeSource AncestorType=DataGrid}"/>
<Binding Path="(hc:DataGridAttach.ShowSelectAllButton)" RelativeSource="{RelativeSource AncestorType=DataGrid}"/>
</MultiBinding>
</Button.Visibility>
</Button>
<DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter" Grid.ColumnSpan="2" Grid.Row="0" Grid.Column="1" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Column}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType=DataGrid}}"/> <DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter" Grid.ColumnSpan="2" Grid.Row="0" Grid.Column="1" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Column}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType=DataGrid}}"/>
<hc:ToggleBlock IsChecked="{Binding HasItems,RelativeSource={RelativeSource AncestorType=DataGrid},Mode=OneWay}" Grid.ColumnSpan="3" Grid.Column="0" Grid.Row="1" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"> <hc:ToggleBlock IsChecked="{Binding HasItems,RelativeSource={RelativeSource AncestorType=DataGrid},Mode=OneWay}" Grid.ColumnSpan="3" Grid.Column="0" Grid.Row="1" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
<hc:ToggleBlock.CheckedContent> <hc:ToggleBlock.CheckedContent>

View File

@ -31,6 +31,7 @@
<converter:Double2GridLengthConverter x:Key="Double2GridLengthConverter" /> <converter:Double2GridLengthConverter x:Key="Double2GridLengthConverter" />
<converter:DoubleMinConverter x:Key="DoubleMinConverter" /> <converter:DoubleMinConverter x:Key="DoubleMinConverter" />
<converter:Object2StringConverter x:Key="Object2StringConverter" /> <converter:Object2StringConverter x:Key="Object2StringConverter" />
<converter:DataGridSelectAllButtonVisibilityConverter x:Key="DataGridSelectAllButtonVisibilityConverter" />
<Color x:Key="EffectShadowColor">#88000000</Color> <Color x:Key="EffectShadowColor">#88000000</Color>
<system:Double x:Key="LargeFontSize">24</system:Double> <system:Double x:Key="LargeFontSize">24</system:Double>
<system:Double x:Key="HeadFontSize">20</system:Double> <system:Double x:Key="HeadFontSize">20</system:Double>
@ -11758,7 +11759,6 @@
<Setter Property="SnapsToDevicePixels" Value="true" /> <Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="Margin" Value="0,0,0,4" /> <Setter Property="Margin" Value="0,0,0,4" />
<Setter Property="Padding" Value="0,6" /> <Setter Property="Padding" Value="0,6" />
<Setter Property="MinHeight" Value="44" />
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}" /> <Setter Property="Validation.ErrorTemplate" Value="{x:Null}" />
<Setter Property="ValidationErrorTemplate"> <Setter Property="ValidationErrorTemplate">
<Setter.Value> <Setter.Value>
@ -11808,8 +11808,7 @@
<Style x:Key="DataGridColumnHeaderStyle" TargetType="DataGridColumnHeader"> <Style x:Key="DataGridColumnHeaderStyle" TargetType="DataGridColumnHeader">
<Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}" /> <Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}" />
<Setter Property="Padding" Value="12,6,12,12" /> <Setter Property="Padding" Value="12,0" />
<Setter Property="MinHeight" Value="44" />
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="DataGridColumnHeader"> <ControlTemplate TargetType="DataGridColumnHeader">
@ -11888,6 +11887,8 @@
<Setter Property="CellStyle" Value="{StaticResource DataGridCellStyle}" /> <Setter Property="CellStyle" Value="{StaticResource DataGridCellStyle}" />
<Setter Property="Padding" Value="6" /> <Setter Property="Padding" Value="6" />
<Setter Property="ColumnWidth" Value="*" /> <Setter Property="ColumnWidth" Value="*" />
<Setter Property="RowHeight" Value="44" />
<Setter Property="ColumnHeaderHeight" Value="44" />
<Setter Property="hc:DataGridAttach.TextColumnStyle" Value="{StaticResource DataGridTextColumnStyle}" /> <Setter Property="hc:DataGridAttach.TextColumnStyle" Value="{StaticResource DataGridTextColumnStyle}" />
<Setter Property="hc:DataGridAttach.EditingTextColumnStyle" Value="{StaticResource TextBoxBaseStyle}" /> <Setter Property="hc:DataGridAttach.EditingTextColumnStyle" Value="{StaticResource TextBoxBaseStyle}" />
<Setter Property="hc:DataGridAttach.ComboBoxColumnStyle" Value="{StaticResource TextBlockComboBoxStyle}" /> <Setter Property="hc:DataGridAttach.ComboBoxColumnStyle" Value="{StaticResource TextBlockComboBoxStyle}" />
@ -11930,7 +11931,14 @@
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Button Command="{x:Static DataGrid.SelectAllCommand}" Margin="0,0,0,6" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.All}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType=DataGrid}}" Width="{Binding CellsPanelHorizontalOffset, RelativeSource={RelativeSource AncestorType=DataGrid},Converter={StaticResource DoubleMinConverter}}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource AllGeometry}" Foreground="{DynamicResource PrimaryBrush}" /> <Button Command="{x:Static DataGrid.SelectAllCommand}" Width="{Binding CellsPanelHorizontalOffset, RelativeSource={RelativeSource AncestorType=DataGrid},Converter={StaticResource DoubleMinConverter}}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource AllGeometry}" Foreground="{DynamicResource PrimaryBrush}">
<Button.Visibility>
<MultiBinding Converter="{StaticResource DataGridSelectAllButtonVisibilityConverter}">
<Binding Path="HeadersVisibility" RelativeSource="{RelativeSource AncestorType=DataGrid}" />
<Binding Path="(hc:DataGridAttach.ShowSelectAllButton)" RelativeSource="{RelativeSource AncestorType=DataGrid}" />
</MultiBinding>
</Button.Visibility>
</Button>
<DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter" Grid.ColumnSpan="2" Grid.Row="0" Grid.Column="1" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Column}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType=DataGrid}}" /> <DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter" Grid.ColumnSpan="2" Grid.Row="0" Grid.Column="1" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Column}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType=DataGrid}}" />
<hc:ToggleBlock IsChecked="{Binding HasItems,RelativeSource={RelativeSource AncestorType=DataGrid},Mode=OneWay}" Grid.ColumnSpan="3" Grid.Column="0" Grid.Row="1" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"> <hc:ToggleBlock IsChecked="{Binding HasItems,RelativeSource={RelativeSource AncestorType=DataGrid},Mode=OneWay}" Grid.ColumnSpan="3" Grid.Column="0" Grid.Row="1" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
<hc:ToggleBlock.CheckedContent> <hc:ToggleBlock.CheckedContent>

View File

@ -0,0 +1,60 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
namespace HandyControl.Tools.Converter
{
public class DataGridSelectAllButtonVisibilityConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values == null)
{
return Visibility.Collapsed;
}
if (values.Length != 2)
{
return Visibility.Collapsed;
}
if (values[0] is DataGridHeadersVisibility headersVisibility)
{
if (values[1] is bool showButton)
{
if (headersVisibility == DataGridHeadersVisibility.All)
{
return showButton ? Visibility.Visible : Visibility.Collapsed;
}
return Visibility.Collapsed;
}
return Visibility.Collapsed;
}
else if (values[0] is bool showButton)
{
if (values[1] is DataGridHeadersVisibility visibility)
{
if (visibility == DataGridHeadersVisibility.All)
{
return showButton ? Visibility.Visible : Visibility.Collapsed;
}
return Visibility.Collapsed;
}
return Visibility.Collapsed;
}
return Visibility.Collapsed;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
}