Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit 9eb4aaf

Browse files
committed
Copy result image support
1 parent ca2b6bd commit 9eb4aaf

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

OnnxStack.UI/UserControls/ImageResultControl.xaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
xmlns:behaviors="clr-namespace:OnnxStack.UI.Behaviors"
99
xmlns:models="clr-namespace:OnnxStack.UI.Models"
1010
mc:Ignorable="d"
11-
d:DesignWidth="500" Name="UI">
11+
d:DesignWidth="500" Name="UI" Focusable="True" PreviewKeyDown="OnPreviewKeyDown" MouseEnter="OnMouseEnter">
1212
<UserControl.Resources>
1313
<Style TargetType="{x:Type Label}">
1414
<Setter Property="Margin" Value="-4,0,0,-4"/>
@@ -17,7 +17,13 @@
1717

1818
<Border DataContext="{Binding ElementName=UI}" BorderBrush="LightGray" BorderThickness="2" >
1919
<StackPanel Margin="2">
20-
<Image Source="{Binding Result.Image, FallbackValue={StaticResource PlaceholderImage}, TargetNullValue={StaticResource PlaceholderImage}}" Width="{Binding SchedulerOptions.Width, FallbackValue=512}" Height="{Binding SchedulerOptions.Height, FallbackValue=512}" MinHeight="512" MinWidth="512"/>
20+
<Image Source="{Binding Result.Image, FallbackValue={StaticResource PlaceholderImage}, TargetNullValue={StaticResource PlaceholderImage}}" Width="{Binding SchedulerOptions.Width, FallbackValue=512}" Height="{Binding SchedulerOptions.Height, FallbackValue=512}" MinHeight="512" MinWidth="512" >
21+
<Image.ContextMenu>
22+
<ContextMenu>
23+
<MenuItem Header="Copy" Command="{Binding CopyImageCommand}" />
24+
</ContextMenu>
25+
</Image.ContextMenu>
26+
</Image>
2127
<StackPanel Visibility="{Binding HasResult, Converter={StaticResource InverseBooleanToVisibilityConverter}}" Margin="0,4">
2228
<ProgressBar Maximum="{Binding ProgressMax}" behaviors:SmoothProgressBarBehavior.SmoothValue="{Binding ProgressValue}" Height="22" />
2329
</StackPanel>

OnnxStack.UI/UserControls/ImageResultControl.xaml.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using System.Windows;
77
using System.Windows.Controls;
8+
using System.Windows.Input;
89

910
namespace OnnxStack.UI.UserControls
1011
{
@@ -14,10 +15,12 @@ public partial class ImageResultControl : UserControl, INotifyPropertyChanged
1415
/// <summary>Initializes a new instance of the <see cref="ImageResultControl" /> class.</summary>
1516
public ImageResultControl()
1617
{
18+
CopyImageCommand = new AsyncRelayCommand(CopyImage);
1719
UpdateSeedCommand = new AsyncRelayCommand<int>(UpdateSeed);
1820
InitializeComponent();
1921
}
2022

23+
public AsyncRelayCommand CopyImageCommand { get; }
2124
public AsyncRelayCommand<int> UpdateSeedCommand { get; }
2225

2326
public ImageResult Result
@@ -77,6 +80,29 @@ private Task UpdateSeed(int previousSeed)
7780
return Task.CompletedTask;
7881
}
7982

83+
private Task CopyImage()
84+
{
85+
if (Result?.Image != null)
86+
Clipboard.SetImage(Result.Image);
87+
88+
return Task.CompletedTask;
89+
}
90+
91+
private async void OnPreviewKeyDown(object sender, KeyEventArgs e)
92+
{
93+
if (e.Key == Key.C && Keyboard.Modifiers == ModifierKeys.Control)
94+
{
95+
await CopyImage();
96+
e.Handled = true;
97+
}
98+
}
99+
100+
private void OnMouseEnter(object sender, MouseEventArgs e)
101+
{
102+
Focus();
103+
}
104+
105+
80106
#region INotifyPropertyChanged
81107
public event PropertyChangedEventHandler PropertyChanged;
82108
public void NotifyPropertyChanged([CallerMemberName] string property = "")

0 commit comments

Comments
 (0)