Skip to content

Commit 28e9632

Browse files
committed
feat: 添加了平滑滚动功能
1 parent 318cd2f commit 28e9632

File tree

10 files changed

+531
-101
lines changed

10 files changed

+531
-101
lines changed

src/CurvaLauncher/CurvaLauncher.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
<ItemGroup>
2727
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
2828
<PackageReference Include="EleCho.GlobalHotkey.Windows" Version="1.0.2" />
29-
<PackageReference Include="EleCho.WpfUtilities.BindingProxy" Version="1.0.0" />
30-
<PackageReference Include="EleCho.WpfUtilities.ConditionControls" Version="1.0.0" />
29+
<PackageReference Include="EleCho.WpfSuite" Version="0.8.1" />
3130
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
3231
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
3332
<PackageReference Include="SharpVectors.Wpf" Version="1.8.2" />

src/CurvaLauncher/MainWindow.xaml

Lines changed: 68 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
xmlns:behaviors="http://schemas.microsoft.com/xaml/behaviors"
99
xmlns:utils="clr-namespace:CurvaLauncher.Utilities"
1010
xmlns:models="clr-namespace:CurvaLauncher.Models"
11-
xmlns:wpfproxy="clr-namespace:EleCho.WpfUtilities;assembly=EleCho.WpfUtilities.BindingProxy"
12-
xmlns:condition="clr-namespace:EleCho.WpfUtilities.ConditionControls;assembly=EleCho.WpfUtilities.ConditionControls"
11+
xmlns:ws="https://schemas.elecho.dev/wpfsuite"
1312
xmlns:tb="http://www.hardcodet.net/taskbar"
1413
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
1514
mc:Ignorable="d"
@@ -105,79 +104,77 @@
105104
</ui:ProgressRing.LayoutTransform>
106105
</ui:ProgressRing>
107106
</Grid>
108-
<condition:IfControl Condition="{Binding ViewModel.HasQueryResult}">
109-
<condition:IfControl.Then>
110-
<ListView Name="resultBox" Margin="0 5 0 0" MinHeight="0"
111-
Height="Auto"
112-
MaxHeight="{Binding AppConfig.LauncherResultViewHeight}"
113-
BorderThickness="0"
114-
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
115-
ScrollViewer.VerticalScrollBarVisibility="Auto"
116-
ItemsSource="{Binding ViewModel.QueryResults}" d:ItemsSource="{d:SampleData ItemCount=5}"
117-
SelectedItem="{Binding ViewModel.SelectedQueryResult,Mode=OneWayToSource}"
118-
SelectedIndex="{Binding ViewModel.SelectedQueryResultIndex}">
119-
<behaviors:Interaction.Triggers>
120-
<behaviors:EventTrigger EventName="SelectionChanged">
121-
<behaviors:InvokeCommandAction Command="{Binding ScrollToSelectedQueryResultCommand}"/>
122-
</behaviors:EventTrigger>
123-
</behaviors:Interaction.Triggers>
124-
<ListView.ItemTemplate>
125-
<DataTemplate DataType="models:QueryResultModel">
126-
<Border Padding="{DynamicResource QueryResultPaddingThickness}">
127-
<Border.Resources>
128-
<wpfproxy:BindingProxy x:Key="Proxy" Data="{Binding}"/>
129-
</Border.Resources>
130-
<Button Command="{Binding InvokeCommand}">
131-
<Button.Template>
132-
<ControlTemplate TargetType="Button">
133-
<ContentPresenter Content="{TemplateBinding Content}"/>
134-
</ControlTemplate>
135-
</Button.Template>
107+
<ws:ConditionalControl Condition="{Binding ViewModel.HasQueryResult}">
108+
<ListView Name="resultBox" Margin="0 5 0 0" MinHeight="0"
109+
Height="Auto"
110+
MaxHeight="{Binding AppConfig.LauncherResultViewHeight}"
111+
BorderThickness="0"
112+
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
113+
ScrollViewer.VerticalScrollBarVisibility="Auto"
114+
ItemsSource="{Binding ViewModel.QueryResults}" d:ItemsSource="{d:SampleData ItemCount=5}"
115+
SelectedItem="{Binding ViewModel.SelectedQueryResult,Mode=OneWayToSource}"
116+
SelectedIndex="{Binding ViewModel.SelectedQueryResultIndex}">
117+
<behaviors:Interaction.Triggers>
118+
<behaviors:EventTrigger EventName="SelectionChanged">
119+
<behaviors:InvokeCommandAction Command="{Binding ScrollToSelectedQueryResultCommand}"/>
120+
</behaviors:EventTrigger>
121+
</behaviors:Interaction.Triggers>
122+
<ListView.ItemTemplate>
123+
<DataTemplate DataType="models:QueryResultModel">
124+
<Border Padding="{DynamicResource QueryResultPaddingThickness}">
125+
<Border.Resources>
126+
<ws:BindingProxy x:Key="Proxy" Data="{Binding}"/>
127+
</Border.Resources>
128+
<Button Command="{Binding InvokeCommand}">
129+
<Button.Template>
130+
<ControlTemplate TargetType="Button">
131+
<ContentPresenter Content="{TemplateBinding Content}"/>
132+
</ControlTemplate>
133+
</Button.Template>
136134

137-
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
138-
<Grid.ColumnDefinitions>
139-
<ColumnDefinition Width="Auto"/>
140-
<ColumnDefinition Width="8"/>
141-
<ColumnDefinition/>
142-
</Grid.ColumnDefinitions>
135+
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
136+
<Grid.ColumnDefinitions>
137+
<ColumnDefinition Width="Auto"/>
138+
<ColumnDefinition Width="8"/>
139+
<ColumnDefinition/>
140+
</Grid.ColumnDefinitions>
143141

144-
<Border Width="{DynamicResource QueryResultIconSize}"
145-
Height="{DynamicResource QueryResultIconSize}"
146-
CornerRadius="{DynamicResource QueryResultIconCornerRadius}">
147-
<Border.Background>
148-
<ImageBrush Stretch="Uniform"
149-
ImageSource="{Binding Source={StaticResource Proxy}, Path=Data.Icon}"/>
150-
</Border.Background>
151-
</Border>
142+
<Border Width="{DynamicResource QueryResultIconSize}"
143+
Height="{DynamicResource QueryResultIconSize}"
144+
CornerRadius="{DynamicResource QueryResultIconCornerRadius}">
145+
<Border.Background>
146+
<ImageBrush Stretch="Uniform"
147+
ImageSource="{Binding Source={StaticResource Proxy}, Path=Data.Icon}"/>
148+
</Border.Background>
149+
</Border>
152150

153-
<Grid Grid.Column="2">
154-
<Grid.RowDefinitions>
155-
<RowDefinition/>
156-
<RowDefinition/>
157-
</Grid.RowDefinitions>
158-
<TextBlock Text="{Binding Title}"
159-
FontSize="{DynamicResource QueryResultTitleTextSize}"
160-
Foreground="{DynamicResource TextFillColorPrimaryBrush}"/>
161-
<TextBlock Grid.Row="1"
162-
TextTrimming="WordEllipsis"
163-
Text="{Binding Description}"
164-
FontSize="{DynamicResource QueryResultDescriptionTextSize}"
165-
Foreground="{DynamicResource TextFillColorSecondaryBrush}"/>
166-
</Grid>
151+
<Grid Grid.Column="2">
152+
<Grid.RowDefinitions>
153+
<RowDefinition/>
154+
<RowDefinition/>
155+
</Grid.RowDefinitions>
156+
<TextBlock Text="{Binding Title}"
157+
FontSize="{DynamicResource QueryResultTitleTextSize}"
158+
Foreground="{DynamicResource TextFillColorPrimaryBrush}"/>
159+
<TextBlock Grid.Row="1"
160+
TextTrimming="WordEllipsis"
161+
Text="{Binding Description}"
162+
FontSize="{DynamicResource QueryResultDescriptionTextSize}"
163+
Foreground="{DynamicResource TextFillColorSecondaryBrush}"/>
167164
</Grid>
168-
</Button>
169-
</Border>
170-
</DataTemplate>
171-
</ListView.ItemTemplate>
172-
<ListView.ItemContainerStyle>
173-
<Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource {x:Type ListViewItem}}">
174-
<Setter Property="BorderThickness" Value="0" />
175-
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
176-
</Style>
177-
</ListView.ItemContainerStyle>
178-
</ListView>
179-
</condition:IfControl.Then>
180-
</condition:IfControl>
165+
</Grid>
166+
</Button>
167+
</Border>
168+
</DataTemplate>
169+
</ListView.ItemTemplate>
170+
<ListView.ItemContainerStyle>
171+
<Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource {x:Type ListViewItem}}">
172+
<Setter Property="BorderThickness" Value="0" />
173+
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
174+
</Style>
175+
</ListView.ItemContainerStyle>
176+
</ListView>
177+
</ws:ConditionalControl>
181178
</StackPanel>
182179
</Border>
183180

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Windows;
2+
3+
namespace CurvaLauncher.Utilities;
4+
5+
static partial class ScrollViewerUtils
6+
{
7+
public record class SmoothScrollingData
8+
{
9+
public bool IsAnimationRunning { get; set; }
10+
public int LastScrollDelta { get; set; }
11+
public int LastVerticalScrollingDelta { get; set; }
12+
public int LastHorizontalScrollingDelta { get; set; }
13+
public long LastScrollingTick { get; set; }
14+
public double HorizontalOffsetTarget { get; set; }
15+
public double VerticalOffsetTarget { get; set; }
16+
17+
public FrameworkElement? ScrollContentPresenter { get; set; }
18+
}
19+
}

0 commit comments

Comments
 (0)