Browse Source

wip. ControlCatalog. handling of bitmap formats in clipboard

pull/12246/head
Vitaliy Orazov 3 years ago
parent
commit
2f51fec236
  1. 8
      samples/ControlCatalog/Pages/ClipboardPage.xaml
  2. 31
      samples/ControlCatalog/Pages/ClipboardPage.xaml.cs

8
samples/ControlCatalog/Pages/ClipboardPage.xaml

@ -12,12 +12,16 @@
<Button Click="CopyFilesDataObject" Content="Copy files to clipboard (data object)" />
<Button Click="PasteFilesDataObject" Content="Paste files from clipboard (data object)" />
<Button Click="CopyBitmapDataObject" Content="Copy bitmap (CF_DIB, image/bmp) to clipboard (data object)" />
<Button Click="PasteBitmapDataObject" Content="Paste bitmap (CF_DIB, image/bmp) from clipboard (data object)" />
<Button Click="GetFormats" Content="Get clipboard formats" />
<Button Click="Clear" Content="Clear clipboard" />
<TextBox x:Name="ClipboardContent"
MinHeight="100"
MinHeight="400"
AcceptsReturn="True"
Watermark="Text to copy of file names per line" />
Watermark="Text to copy of file names per line"
TextWrapping="Wrap"/>
</StackPanel>
</UserControl>

31
samples/ControlCatalog/Pages/ClipboardPage.xaml.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Notifications;
@ -118,6 +119,36 @@ namespace ControlCatalog.Pages
}
}
private void CopyBitmapDataObject(object? sender, RoutedEventArgs args)
{
if (TopLevel.GetTopLevel(this)?.Clipboard is { } clipboard)
{
}
}
private async void PasteBitmapDataObject(object? sender, RoutedEventArgs args)
{
if (TopLevel.GetTopLevel(this)?.Clipboard is { } clipboard)
{
var bytes = await clipboard.GetDataAsync("Bitmap") as IEnumerable<byte>
?? await clipboard.GetDataAsync("Dib") as IEnumerable<byte>;
if (bytes != null)
{
var printable = bytes.Take(1000);
var sb = new StringBuilder(256 + printable.Count() * 3);
sb.AppendLine($"{bytes.Count()} bytes, list of first {printable.Count()}");
sb.AppendJoin(" ", printable.Select(x => x.ToString("X2")));
ClipboardContent.Text = sb.ToString();
}
else
{
ClipboardContent.Text = string.Empty;
}
}
}
private async void GetFormats(object sender, RoutedEventArgs args)
{
if (TopLevel.GetTopLevel(this)?.Clipboard is { } clipboard)

Loading…
Cancel
Save