Skip to content

Commit

Permalink
chore(style): add ListView small style.
Browse files Browse the repository at this point in the history
  • Loading branch information
NaBian committed Jun 17, 2022
1 parent ad5de3a commit a484306
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 85 deletions.
46 changes: 29 additions & 17 deletions src/Net_40/HandyControl_Net_40/Themes/Styles/ListView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,28 @@
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="ItemContainerStyle" Value="{StaticResource ListViewItemBaseStyle}"/>
<Setter Property="hc:GridViewAttach.ColumnHeaderHeight" Value="44" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListView">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
<hc:ToggleBlock IsChecked="{Binding HasItems,RelativeSource={RelativeSource TemplatedParent},Mode=OneWay}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
<hc:ToggleBlock.CheckedContent>
<ScrollViewer>
<Grid Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<GridViewHeaderRowPresenter AllowsColumnReorder="{Binding View.AllowsColumnReorder, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderContainerStyle="{Binding View.ColumnHeaderContainerStyle, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderToolTip="{Binding View.ColumnHeaderToolTip, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderContextMenu="{Binding View.ColumnHeaderContextMenu, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderTemplate="{Binding View.ColumnHeaderTemplate, RelativeSource={RelativeSource TemplatedParent}}" Columns="{Binding View.Columns, RelativeSource={RelativeSource TemplatedParent}}" Margin="2,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
<ItemsPresenter Grid.Row="1" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Grid>
</ScrollViewer>
</hc:ToggleBlock.CheckedContent>
<hc:ToggleBlock.UnCheckedContent>
<hc:Empty />
</hc:ToggleBlock.UnCheckedContent>
</hc:ToggleBlock>
<Grid Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<GridViewHeaderRowPresenter AllowsColumnReorder="{Binding View.AllowsColumnReorder, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderContainerStyle="{Binding View.ColumnHeaderContainerStyle, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderToolTip="{Binding View.ColumnHeaderToolTip, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderContextMenu="{Binding View.ColumnHeaderContextMenu, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderTemplate="{Binding View.ColumnHeaderTemplate, RelativeSource={RelativeSource TemplatedParent}}" Columns="{Binding View.Columns, RelativeSource={RelativeSource TemplatedParent}}" Margin="2,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<hc:ToggleBlock Grid.Row="1" IsChecked="{Binding HasItems,RelativeSource={RelativeSource TemplatedParent},Mode=OneWay}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
<hc:ToggleBlock.CheckedContent>
<ScrollViewer>
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</ScrollViewer>
</hc:ToggleBlock.CheckedContent>
<hc:ToggleBlock.UnCheckedContent>
<hc:Empty />
</hc:ToggleBlock.UnCheckedContent>
</hc:ToggleBlock>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
Expand All @@ -44,4 +45,15 @@

<Style BasedOn="{StaticResource ListViewBaseStyle}" TargetType="ListView"/>

<Style x:Key="ListViewItemBaseStyle.Small" BasedOn="{StaticResource ListViewItemBaseStyle}" TargetType="ListViewItem">
<Setter Property="Padding" Value="6,2" />
<Setter Property="MinHeight" Value="24" />
<Setter Property="Margin" Value="0,0,0,2" />
</Style>

<Style x:Key="ListView.Small" BasedOn="{StaticResource ListViewBaseStyle}" TargetType="ListView">
<Setter Property="ItemContainerStyle" Value="{StaticResource ListViewItemBaseStyle.Small}" />
<Setter Property="hc:GridViewAttach.ColumnHeaderHeight" Value="30" />
</Style>

</ResourceDictionary>
48 changes: 29 additions & 19 deletions src/Net_40/HandyControl_Net_40/Themes/Theme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9503,8 +9503,8 @@
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}" />
<Setter Property="Padding" Value="12,6,12,12" />
<Setter Property="MinHeight" Value="44" />
<Setter Property="Padding" Value="12,0" />
<Setter Property="MinHeight" Value="{Binding Path=(hc:GridViewAttach.ColumnHeaderHeight),RelativeSource={RelativeSource AncestorType=ListView}}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GridViewColumnHeader">
Expand Down Expand Up @@ -12938,33 +12938,43 @@
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="ItemContainerStyle" Value="{StaticResource ListViewItemBaseStyle}" />
<Setter Property="hc:GridViewAttach.ColumnHeaderHeight" Value="44" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListView">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
<hc:ToggleBlock IsChecked="{Binding HasItems,RelativeSource={RelativeSource TemplatedParent},Mode=OneWay}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
<hc:ToggleBlock.CheckedContent>
<ScrollViewer>
<Grid Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<GridViewHeaderRowPresenter AllowsColumnReorder="{Binding View.AllowsColumnReorder, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderContainerStyle="{Binding View.ColumnHeaderContainerStyle, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderToolTip="{Binding View.ColumnHeaderToolTip, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderContextMenu="{Binding View.ColumnHeaderContextMenu, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderTemplate="{Binding View.ColumnHeaderTemplate, RelativeSource={RelativeSource TemplatedParent}}" Columns="{Binding View.Columns, RelativeSource={RelativeSource TemplatedParent}}" Margin="2,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<ItemsPresenter Grid.Row="1" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Grid>
</ScrollViewer>
</hc:ToggleBlock.CheckedContent>
<hc:ToggleBlock.UnCheckedContent>
<hc:Empty />
</hc:ToggleBlock.UnCheckedContent>
</hc:ToggleBlock>
<Grid Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<GridViewHeaderRowPresenter AllowsColumnReorder="{Binding View.AllowsColumnReorder, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderContainerStyle="{Binding View.ColumnHeaderContainerStyle, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderToolTip="{Binding View.ColumnHeaderToolTip, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderContextMenu="{Binding View.ColumnHeaderContextMenu, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderTemplate="{Binding View.ColumnHeaderTemplate, RelativeSource={RelativeSource TemplatedParent}}" Columns="{Binding View.Columns, RelativeSource={RelativeSource TemplatedParent}}" Margin="2,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<hc:ToggleBlock Grid.Row="1" IsChecked="{Binding HasItems,RelativeSource={RelativeSource TemplatedParent},Mode=OneWay}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
<hc:ToggleBlock.CheckedContent>
<ScrollViewer>
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</ScrollViewer>
</hc:ToggleBlock.CheckedContent>
<hc:ToggleBlock.UnCheckedContent>
<hc:Empty />
</hc:ToggleBlock.UnCheckedContent>
</hc:ToggleBlock>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style BasedOn="{StaticResource ListViewBaseStyle}" TargetType="ListView" />
<Style x:Key="ListViewItemBaseStyle.Small" BasedOn="{StaticResource ListViewItemBaseStyle}" TargetType="ListViewItem">
<Setter Property="Padding" Value="6,2" />
<Setter Property="MinHeight" Value="24" />
<Setter Property="Margin" Value="0,0,0,2" />
</Style>
<Style x:Key="ListView.Small" BasedOn="{StaticResource ListViewBaseStyle}" TargetType="ListView">
<Setter Property="ItemContainerStyle" Value="{StaticResource ListViewItemBaseStyle.Small}" />
<Setter Property="hc:GridViewAttach.ColumnHeaderHeight" Value="30" />
</Style>
<Style BasedOn="{StaticResource LoadingLineBaseStyle}" TargetType="hc:LoadingLine" />
<Style x:Key="LoadingLineLight" BasedOn="{StaticResource LoadingLineBaseStyle}" TargetType="hc:LoadingLine">
<Setter Property="Foreground" Value="{DynamicResource TextIconBrush}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<hc:TransitioningContentControl>
<TabControl Style="{StaticResource TabControlInLine}">
<TabItem Header="{ex:Lang Key={x:Static langs:LangKeys.Common}}">
<DataGrid hc:DataGridAttach.CanUnselectAllWithBlankArea="True" HeadersVisibility="All" RowHeaderWidth="60" AutoGenerateColumns="False" ItemsSource="{Binding DataList}">
<DataGrid Style="{StaticResource DataGrid.Small}" hc:DataGridAttach.CanUnselectAllWithBlankArea="True" HeadersVisibility="All" RowHeaderWidth="60" AutoGenerateColumns="False" ItemsSource="{Binding DataList}">
<DataGrid.RowHeaderTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsSelected,RelativeSource={RelativeSource AncestorType=DataGridRow}}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,29 @@
xmlns:ex="clr-namespace:HandyControlDemo.Tools.Extension"
Background="{DynamicResource RegionBrush}">
<hc:TransitioningContentControl>
<ListView ItemsSource="{Binding DataList}">
<ListView.View>
<GridView>
<GridViewColumn Width="80" Header="{ex:Lang Key={x:Static langs:LangKeys.Index}}" DisplayMemberBinding="{Binding Index}"/>
<GridViewColumn Width="100" Header="{ex:Lang Key={x:Static langs:LangKeys.Name}}" DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn Width="200" Header="{ex:Lang Key={x:Static langs:LangKeys.Remark}}" DisplayMemberBinding="{Binding Remark}"/>
</GridView>
</ListView.View>
</ListView>
<TabControl Style="{StaticResource TabControlInLine}">
<TabItem Header="Default">
<ListView ItemsSource="{Binding DataList}">
<ListView.View>
<GridView>
<GridViewColumn Width="80" Header="{ex:Lang Key={x:Static langs:LangKeys.Index}}" DisplayMemberBinding="{Binding Index}" />
<GridViewColumn Width="100" Header="{ex:Lang Key={x:Static langs:LangKeys.Name}}" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Width="200" Header="{ex:Lang Key={x:Static langs:LangKeys.Remark}}" DisplayMemberBinding="{Binding Remark}" />
</GridView>
</ListView.View>
</ListView>
</TabItem>
<TabItem Header="Small">
<ListView ItemsSource="{Binding DataList}" Style="{StaticResource ListView.Small}">
<ListView.View>
<GridView>
<GridViewColumn Width="80" Header="{ex:Lang Key={x:Static langs:LangKeys.Index}}" DisplayMemberBinding="{Binding Index}" />
<GridViewColumn Width="100" Header="{ex:Lang Key={x:Static langs:LangKeys.Name}}" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Width="200" Header="{ex:Lang Key={x:Static langs:LangKeys.Remark}}" DisplayMemberBinding="{Binding Remark}" />
</GridView>
</ListView.View>
</ListView>
</TabItem>
</TabControl>
</hc:TransitioningContentControl>
</UserControl>
16 changes: 16 additions & 0 deletions src/Shared/HandyControl_Shared/Controls/Attach/GridViewAttach.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Windows;
using HandyControl.Data;

namespace HandyControl.Controls;

public class GridViewAttach
{
public static readonly DependencyProperty ColumnHeaderHeightProperty = DependencyProperty.RegisterAttached(
"ColumnHeaderHeight", typeof(double), typeof(GridViewAttach), new PropertyMetadata(ValueBoxes.Double0Box));

public static void SetColumnHeaderHeight(DependencyObject element, double value)
=> element.SetValue(ColumnHeaderHeightProperty, value);

public static double GetColumnHeaderHeight(DependencyObject element)
=> (double) element.GetValue(ColumnHeaderHeightProperty);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\DropDownElement.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\EdgeElement.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\GridAttach.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\GridViewAttach.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\IconElement.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\IconSwitchElement.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\ImageAttach.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"/>
<Setter Property="Padding" Value="12,6,12,12"/>
<Setter Property="MinHeight" Value="44"/>
<Setter Property="Padding" Value="12,0" />
<Setter Property="MinHeight" Value="{Binding Path=(hc:GridViewAttach.ColumnHeaderHeight),RelativeSource={RelativeSource AncestorType=ListView}}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GridViewColumnHeader">
Expand Down
Loading

0 comments on commit a484306

Please sign in to comment.