Skip to content

Commit

Permalink
feat: 添加了平滑滚动功能
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimeNull committed Sep 11, 2024
1 parent 318cd2f commit 28e9632
Show file tree
Hide file tree
Showing 10 changed files with 531 additions and 101 deletions.
3 changes: 1 addition & 2 deletions src/CurvaLauncher/CurvaLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
<PackageReference Include="EleCho.GlobalHotkey.Windows" Version="1.0.2" />
<PackageReference Include="EleCho.WpfUtilities.BindingProxy" Version="1.0.0" />
<PackageReference Include="EleCho.WpfUtilities.ConditionControls" Version="1.0.0" />
<PackageReference Include="EleCho.WpfSuite" Version="0.8.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
<PackageReference Include="SharpVectors.Wpf" Version="1.8.2" />
Expand Down
139 changes: 68 additions & 71 deletions src/CurvaLauncher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
xmlns:behaviors="http://schemas.microsoft.com/xaml/behaviors"
xmlns:utils="clr-namespace:CurvaLauncher.Utilities"
xmlns:models="clr-namespace:CurvaLauncher.Models"
xmlns:wpfproxy="clr-namespace:EleCho.WpfUtilities;assembly=EleCho.WpfUtilities.BindingProxy"
xmlns:condition="clr-namespace:EleCho.WpfUtilities.ConditionControls;assembly=EleCho.WpfUtilities.ConditionControls"
xmlns:ws="https://schemas.elecho.dev/wpfsuite"
xmlns:tb="http://www.hardcodet.net/taskbar"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
mc:Ignorable="d"
Expand Down Expand Up @@ -105,79 +104,77 @@
</ui:ProgressRing.LayoutTransform>
</ui:ProgressRing>
</Grid>
<condition:IfControl Condition="{Binding ViewModel.HasQueryResult}">
<condition:IfControl.Then>
<ListView Name="resultBox" Margin="0 5 0 0" MinHeight="0"
Height="Auto"
MaxHeight="{Binding AppConfig.LauncherResultViewHeight}"
BorderThickness="0"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ItemsSource="{Binding ViewModel.QueryResults}" d:ItemsSource="{d:SampleData ItemCount=5}"
SelectedItem="{Binding ViewModel.SelectedQueryResult,Mode=OneWayToSource}"
SelectedIndex="{Binding ViewModel.SelectedQueryResultIndex}">
<behaviors:Interaction.Triggers>
<behaviors:EventTrigger EventName="SelectionChanged">
<behaviors:InvokeCommandAction Command="{Binding ScrollToSelectedQueryResultCommand}"/>
</behaviors:EventTrigger>
</behaviors:Interaction.Triggers>
<ListView.ItemTemplate>
<DataTemplate DataType="models:QueryResultModel">
<Border Padding="{DynamicResource QueryResultPaddingThickness}">
<Border.Resources>
<wpfproxy:BindingProxy x:Key="Proxy" Data="{Binding}"/>
</Border.Resources>
<Button Command="{Binding InvokeCommand}">
<Button.Template>
<ControlTemplate TargetType="Button">
<ContentPresenter Content="{TemplateBinding Content}"/>
</ControlTemplate>
</Button.Template>
<ws:ConditionalControl Condition="{Binding ViewModel.HasQueryResult}">
<ListView Name="resultBox" Margin="0 5 0 0" MinHeight="0"
Height="Auto"
MaxHeight="{Binding AppConfig.LauncherResultViewHeight}"
BorderThickness="0"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ItemsSource="{Binding ViewModel.QueryResults}" d:ItemsSource="{d:SampleData ItemCount=5}"
SelectedItem="{Binding ViewModel.SelectedQueryResult,Mode=OneWayToSource}"
SelectedIndex="{Binding ViewModel.SelectedQueryResultIndex}">
<behaviors:Interaction.Triggers>
<behaviors:EventTrigger EventName="SelectionChanged">
<behaviors:InvokeCommandAction Command="{Binding ScrollToSelectedQueryResultCommand}"/>
</behaviors:EventTrigger>
</behaviors:Interaction.Triggers>
<ListView.ItemTemplate>
<DataTemplate DataType="models:QueryResultModel">
<Border Padding="{DynamicResource QueryResultPaddingThickness}">
<Border.Resources>
<ws:BindingProxy x:Key="Proxy" Data="{Binding}"/>
</Border.Resources>
<Button Command="{Binding InvokeCommand}">
<Button.Template>
<ControlTemplate TargetType="Button">
<ContentPresenter Content="{TemplateBinding Content}"/>
</ControlTemplate>
</Button.Template>

<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="8"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="8"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>

<Border Width="{DynamicResource QueryResultIconSize}"
Height="{DynamicResource QueryResultIconSize}"
CornerRadius="{DynamicResource QueryResultIconCornerRadius}">
<Border.Background>
<ImageBrush Stretch="Uniform"
ImageSource="{Binding Source={StaticResource Proxy}, Path=Data.Icon}"/>
</Border.Background>
</Border>
<Border Width="{DynamicResource QueryResultIconSize}"
Height="{DynamicResource QueryResultIconSize}"
CornerRadius="{DynamicResource QueryResultIconCornerRadius}">
<Border.Background>
<ImageBrush Stretch="Uniform"
ImageSource="{Binding Source={StaticResource Proxy}, Path=Data.Icon}"/>
</Border.Background>
</Border>

<Grid Grid.Column="2">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding Title}"
FontSize="{DynamicResource QueryResultTitleTextSize}"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"/>
<TextBlock Grid.Row="1"
TextTrimming="WordEllipsis"
Text="{Binding Description}"
FontSize="{DynamicResource QueryResultDescriptionTextSize}"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"/>
</Grid>
<Grid Grid.Column="2">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding Title}"
FontSize="{DynamicResource QueryResultTitleTextSize}"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"/>
<TextBlock Grid.Row="1"
TextTrimming="WordEllipsis"
Text="{Binding Description}"
FontSize="{DynamicResource QueryResultDescriptionTextSize}"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"/>
</Grid>
</Button>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource {x:Type ListViewItem}}">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListView.ItemContainerStyle>
</ListView>
</condition:IfControl.Then>
</condition:IfControl>
</Grid>
</Button>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource {x:Type ListViewItem}}">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListView.ItemContainerStyle>
</ListView>
</ws:ConditionalControl>
</StackPanel>
</Border>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Windows;

namespace CurvaLauncher.Utilities;

static partial class ScrollViewerUtils
{
public record class SmoothScrollingData
{
public bool IsAnimationRunning { get; set; }
public int LastScrollDelta { get; set; }
public int LastVerticalScrollingDelta { get; set; }
public int LastHorizontalScrollingDelta { get; set; }
public long LastScrollingTick { get; set; }
public double HorizontalOffsetTarget { get; set; }
public double VerticalOffsetTarget { get; set; }

public FrameworkElement? ScrollContentPresenter { get; set; }
}
}
Loading

0 comments on commit 28e9632

Please sign in to comment.