Skip to content

Commit

Permalink
perf: 更新案例
Browse files Browse the repository at this point in the history
  • Loading branch information
ZGGSONG committed Jul 30, 2024
1 parent 04518bb commit d9e7304
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 38 deletions.
17 changes: 9 additions & 8 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Dapplo.Windows.User32" Version="1.0.28"/>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0"/>
<PackageVersion Include="xunit" Version="2.8.0"/>
</ItemGroup>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Dapplo.Windows.User32" Version="1.0.28" />
<PackageVersion Include="NHotkey" Version="3.0.0" />
<PackageVersion Include="NHotkey.Wpf" Version="3.0.0" />
<PackageVersion Include="WPF-UI" Version="3.0.5" />
</ItemGroup>
</Project>
9 changes: 7 additions & 2 deletions tests/ScreenGrab.Sample/App.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<Application x:Class="ScreenGrab.Sample.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ScreenGrab.Sample"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>

<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:ThemesDictionary Theme="Dark" />
<ui:ControlsDictionary />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
11 changes: 2 additions & 9 deletions tests/ScreenGrab.Sample/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
using System.Configuration;
using System.Data;
using System.Windows;
namespace ScreenGrab.Sample;

namespace ScreenGrab.Sample;

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
public partial class App
{
}
37 changes: 23 additions & 14 deletions tests/ScreenGrab.Sample/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
<Window x:Class="ScreenGrab.Sample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ScreenGrab.Sample"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<ui:FluentWindow x:Class="ScreenGrab.Sample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Loaded="MainWindow_OnLoaded"
Unloaded="MainWindow_OnUnloaded"
WindowStartupLocation="CenterScreen"
Title="ScreenGrab Sample" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="38"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<Button Content="Capture" Click="Capture_Click"/>
<Button Content="Clean" Click="Clean_Click"></Button>
</StackPanel>
<Image Grid.Row="1" x:Name="Img"/>
<ui:TitleBar Title="ScreenGrab Sample" />
<ui:Card Grid.Row="1" Margin="8">
<StackPanel Orientation="Horizontal">
<Button Content="Capture" Margin="2 0" Click="Capture_Click" />
<Button Content="Clean" Margin="2 0" Click="Clean_Click" />
</StackPanel>
</ui:Card>
<ui:DynamicScrollViewer Grid.Row="2" Margin="8">
<Image x:Name="Img" />
</ui:DynamicScrollViewer>
</Grid>
</Window>
</ui:FluentWindow>
30 changes: 25 additions & 5 deletions tests/ScreenGrab.Sample/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using System.Windows;
using System.Windows.Input;
using NHotkey;
using NHotkey.Wpf;
using ScreenGrab.Utilities;

namespace ScreenGrab.Sample;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
}

private void Capture_Click(object sender, RoutedEventArgs e)
private void Capture()
{
Clean();

Expand All @@ -24,6 +24,16 @@ private void Capture_Click(object sender, RoutedEventArgs e)
grab.Capture();
}

private void Capture(object? sender, HotkeyEventArgs e)
{
Capture();
}

private void Capture_Click(object sender, RoutedEventArgs e)
{
Capture();
}

private void Clean_Click(object sender, RoutedEventArgs e)
{
Clean();
Expand All @@ -35,4 +45,14 @@ private void Clean()
Img.Source = null;
GC.Collect();
}

private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{
HotkeyManager.Current.AddOrReplace("Capture", Key.A, ModifierKeys.Windows | ModifierKeys.Shift, Capture);
}

private void MainWindow_OnUnloaded(object sender, RoutedEventArgs e)
{
HotkeyManager.Current.Remove("Capture");
}
}
6 changes: 6 additions & 0 deletions tests/ScreenGrab.Sample/ScreenGrab.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@
<ProjectReference Include="..\..\src\ScreenGrab\ScreenGrab.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="NHotkey" />
<PackageReference Include="NHotkey.Wpf" />
<PackageReference Include="WPF-UI" />
</ItemGroup>

</Project>

0 comments on commit d9e7304

Please sign in to comment.