Skip to content

Commit

Permalink
fix: Home page PackagesDataGrid bugs
Browse files Browse the repository at this point in the history
- `DataGridRow`s are now highlighted on mouse click and select by
adding a custom style that fixes
(lepoco/wpfui#410)
- `PackagesDataGrid` now does not overflow the home page and instead
properly displays a scroll bar.

- Also fixed a misc nullability warning in MainWindow.xaml.cs
  • Loading branch information
trungnt2910 committed Sep 27, 2022
1 parent bf3a5a4 commit 47ea833
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 9 deletions.
2 changes: 2 additions & 0 deletions X410Launcher/UI/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<ResourceDictionary.MergedDictionaries>
<wpfui:ThemesDictionary Theme="Dark" />
<wpfui:ControlsDictionary />

<ResourceDictionary Source="pack://application:,,,/UI/Styles/DataGridRow.xaml" />
</ResourceDictionary.MergedDictionaries>

<viewmodels:X410StatusViewModel x:Key="X410StatusViewModel" />
Expand Down
2 changes: 1 addition & 1 deletion X410Launcher/UI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
xmlns:pages="clr-namespace:X410Launcher.UI.Pages"
mc:Ignorable="d"
x:Name="this"
Title="X410Launcher" Height="750" Width="1300"
Title="X410Launcher" Height="720" Width="1280"
Background="{wpfui:ThemeResource ApplicationBackgroundBrush}"
ExtendsContentIntoTitleBar="True"
WindowBackdropType="Mica"
Expand Down
2 changes: 1 addition & 1 deletion X410Launcher/UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public MainWindow()
return null;
}

private void UpdateIcon(object sender, PropertyChangedEventArgs e)
private void UpdateIcon(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(X410StatusViewModel.InstalledVersion))
{
Expand Down
31 changes: 24 additions & 7 deletions X410Launcher/UI/Pages/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
<RowDefinition Height="40"/>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Margin="10">
<TextBlock FontSize="{DynamicResource ControlContentThemeFontSize}">
<Grid Grid.Row="0" Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" FontSize="{DynamicResource ControlContentThemeFontSize}">
<TextBlock.Foreground>
<SolidColorBrush Color="{DynamicResource TextFillColorPrimary}" />
</TextBlock.Foreground>
Expand All @@ -27,8 +32,7 @@
<Span>Latest version: </Span>
<Run Text="{Binding LatestVersion, Mode=OneWay}" />
</TextBlock>
<Border Height="10" />
<TextBlock FontSize="{DynamicResource ControlContentThemeFontSize}">
<TextBlock Grid.Row="1" FontSize="{DynamicResource ControlContentThemeFontSize}">
<TextBlock.Foreground>
<SolidColorBrush Color="{DynamicResource TextFillColorPrimary}" />
</TextBlock.Foreground>
Expand All @@ -38,9 +42,22 @@
<Run Text="{Binding AppId, Mode=OneWay}"/>
<Span>:</Span>
</TextBlock>
<DataGrid x:Name="PackagesDataGrid" ItemsSource="{Binding Packages}" IsReadOnly="True">
</DataGrid>
</StackPanel>
<wpfui:DataGrid x:Name="PackagesDataGrid" Grid.Row="2"
ItemsSource="{Binding Packages}" IsReadOnly="True"
RowStyle="{StaticResource DefaultDataGridRowStyle}"
AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Package Name" Binding="{Binding PackageName}" Width="Auto"/>
<DataGridTextColumn Header="Version" Binding="{Binding Version}" Width="Auto"/>
<DataGridTextColumn Header="Size" Binding="{Binding Size}" Width="Auto"/>
<DataGridTextColumn Header="Architecture" Binding="{Binding Architecture}" Width="Auto"/>
<DataGridTextColumn Header="Format" Binding="{Binding Format}" Width="Auto"/>
<DataGridTextColumn Header="SHA1" Binding="{Binding SHA1}" Width="Auto"/>
<DataGridTextColumn Header="Expires at" Binding="{Binding ExpireTime}" Width="Auto"/>
<DataGridTextColumn Header="URL" Binding="{Binding URL}" Width="Auto"/>
</DataGrid.Columns>
</wpfui:DataGrid>
</Grid>
<StackPanel Grid.Row="1" Orientation="Horizontal" FlowDirection="RightToLeft" Margin="10, 0, 10, 0">
<Button x:Name="RefreshButton" Content="Refresh" Click="RefreshButton_Click" />
<Border Width="10"/>
Expand Down
135 changes: 135 additions & 0 deletions X410Launcher/UI/Styles/DataGridRow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- Style and template for the DataGridRow. -->
<Style x:Key="DefaultDataGridRowStyle" TargetType="{x:Type DataGridRow}">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Opacity="0.0" Color="{DynamicResource ControlFillColorDefault}" />
</Setter.Value>
</Setter>
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}" />
<Setter Property="ValidationErrorTemplate">
<Setter.Value>
<ControlTemplate>
<TextBlock
Margin="2,0,0,0"
VerticalAlignment="Center"
Foreground="{DynamicResource SystemFillColorCriticalBrush}"
Text="!" />
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridRow}">
<Border
x:Name="DGR_Border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="True">
<SelectiveScrollingGrid>
<SelectiveScrollingGrid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</SelectiveScrollingGrid.ColumnDefinitions>
<SelectiveScrollingGrid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</SelectiveScrollingGrid.RowDefinitions>
<DataGridCellsPresenter
Grid.Column="1"
ItemsPanel="{TemplateBinding ItemsPanel}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<DataGridDetailsPresenter
Grid.Row="1"
Grid.Column="1"
SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding AreRowDetailsFrozen, ConverterParameter={x:Static SelectiveScrollingOrientation.Vertical}, Converter={x:Static DataGrid.RowDetailsScrollingConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
Visibility="{TemplateBinding DetailsVisibility}" />
<DataGridRowHeader
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="0"
SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical"
Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Row}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />
</SelectiveScrollingGrid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />

<!-- Provide a different appearance for every other row. -->
<VisualState x:Name="Normal_AlternatingRow" />

<VisualState x:Name="Normal_Selected">
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Duration="0" To="{DynamicResource SystemAccentColor}" />
<DoubleAnimation Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Opacity)" Duration="0" To="0.6" />
</Storyboard>
</VisualState>

<VisualState x:Name="Unfocused_Selected">
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Duration="0" To="{DynamicResource SystemAccentColor}" />
<DoubleAnimation Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Opacity)" Duration="0" To="0.6" />
</Storyboard>
</VisualState>

<VisualState x:Name="Normal_Editing">
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Duration="0" To="{DynamicResource SystemAccentColor}" />
<DoubleAnimation Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Opacity)" Duration="0" To="0.6" />
</Storyboard>
</VisualState>

<VisualState x:Name="MouseOver_Editing">
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Duration="0" To="{DynamicResource SystemAccentColor}" />
<DoubleAnimation Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Opacity)" Duration="0" To="0.8" />
</Storyboard>
</VisualState>

<VisualState x:Name="MouseOver_Unfocused_Editing">
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Duration="0" To="{DynamicResource SystemAccentColor}" />
<DoubleAnimation Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Opacity)" Duration="0" To="0.8" />
</Storyboard>
</VisualState>

<VisualState x:Name="Unfocused_Editing">
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Duration="0" To="{DynamicResource SystemAccentColor}" />
<DoubleAnimation Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Opacity)" Duration="0" To="0.6" />
</Storyboard>
</VisualState>

<VisualState x:Name="MouseOver">
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Opacity)" Duration="0" To="0.8" />
</Storyboard>
</VisualState>

<VisualState x:Name="MouseOver_Selected">
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Duration="0" To="{DynamicResource SystemAccentColor}" />
<DoubleAnimation Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Opacity)" Duration="0" To="0.8" />
</Storyboard>
</VisualState>

<VisualState x:Name="MouseOver_Unfocused_Selected">
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Duration="0" To="{DynamicResource SystemAccentColor}" />
<DoubleAnimation Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Opacity)" Duration="0" To="0.8" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

0 comments on commit 47ea833

Please sign in to comment.