Skip to content

Commit

Permalink
feat: DataGrid centered layout style
Browse files Browse the repository at this point in the history
  • Loading branch information
emako committed Oct 27, 2024
1 parent 3861c7d commit 78b21f6
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/Wpf.Ui.Test/Wpf.Ui.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageReference Include="WPF-UI" Version="3.0.5" />
<PackageReference Include="ComputedAnimations.WPF" Version="0.4.6-beta" />
<PackageReference Include="ComputedBehaviors.WPF" Version="0.4.6-beta" />
<PackageReference Include="ComputedConverters.WPF" Version="0.4.6-beta" />
<PackageReference Include="ComputedAnimations.WPF" Version="0.4.7-beta" />
<PackageReference Include="ComputedBehaviors.WPF" Version="0.4.7-beta" />
<PackageReference Include="ComputedConverters.WPF" Version="0.4.7-beta" />
</ItemGroup>

<ItemGroup>
Expand Down
91 changes: 91 additions & 0 deletions src/Wpf.Ui.Violeta/Controls/DataGrid/DataGrid.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<!-- Used for DataGrid.CellStyle -->
<Style
x:Key="CenteredDataGridCellStyle"
BasedOn="{StaticResource DefaultDataGridCellStyle}"
TargetType="{x:Type DataGridCell}">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border
x:Name="Border"
MinWidth="45"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
Background="#01FFFFFF"
BorderThickness="0"
SnapsToDevicePixels="True">
<ContentPresenter
FrameworkElement.HorizontalAlignment="Center"
FrameworkElement.VerticalAlignment="Center"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<!-- Used for DataGrid.ColumnHeaderStyle -->
<Style
x:Key="CenteredDataGridColumnHeaderStyle"
BasedOn="{StaticResource DefaultDataGridColumnHeaderStyle}"
TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock
HorizontalAlignment="Center"
Text="{TemplateBinding Content}"
TextWrapping="Wrap" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>

<!-- Used for DataGridTextColumn.ElementStyle -->
<Style
x:Key="CenteredDataGridTextColumnElementStyle"
BasedOn="{StaticResource {x:Type TextBlock}}"
TargetType="{x:Type TextBlock}">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>

<!-- Used for DataGridTextColumn.EditingElementStyle -->
<Style
x:Key="CenteredDataGridTextColumnEditingElementStyle"
BasedOn="{StaticResource {x:Type TextBox}}"
TargetType="TextBox">
<Setter Property="MinWidth" Value="80" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Center" />
</Style>

<!-- Used for DataGridTextColumn.CellStyle -->
<Style
x:Key="CenteredDataGridTextColumnCellStyle"
BasedOn="{StaticResource DefaultDataGridCellStyle}"
TargetType="{x:Type DataGridCell}">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border
x:Name="Border"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
Background="#01FFFFFF"
BorderThickness="0"
SnapsToDevicePixels="True">
<ContentPresenter
FrameworkElement.HorizontalAlignment="Center"
FrameworkElement.VerticalAlignment="Center"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

</ResourceDictionary>
1 change: 1 addition & 0 deletions src/Wpf.Ui.Violeta/Resources/Wpf.Ui.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
<ResourceDictionary Source="pack://application:,,,/Wpf.Ui.Violeta;component/Controls/TreeModelListView/TreeModelListView.xaml" />
<ResourceDictionary Source="pack://application:,,,/Wpf.Ui.Violeta;component/Controls/TreeListView/TreeListView.xaml" />
<ResourceDictionary Source="pack://application:,,,/Wpf.Ui.Violeta;component/Controls/ContentDialog/ContentDialog.xaml" />
<ResourceDictionary Source="pack://application:,,,/Wpf.Ui.Violeta;component/Controls/DataGrid/DataGrid.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
7 changes: 1 addition & 6 deletions src/Wpf.Ui.Violeta/Wpf.Ui.Violeta.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,7 @@
<PackageReference Include="WPF-UI" Version="3.0.5" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net462' Or
'$(TargetFramework)' == 'net47' Or
'$(TargetFramework)' == 'net471' Or
'$(TargetFramework)' == 'net472' Or
'$(TargetFramework)' == 'net48' Or
'$(TargetFramework)' == 'net481'">
<ItemGroup Condition="'$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'net47' Or '$(TargetFramework)' == 'net471' Or '$(TargetFramework)' == 'net472' Or '$(TargetFramework)' == 'net48' Or '$(TargetFramework)' == 'net481'">
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>

Expand Down

0 comments on commit 78b21f6

Please sign in to comment.