|
@@ -23,55 +23,79 @@ namespace ControlCatalog.Pages
|
|
|
AvaloniaXamlLoader.Load(this);
|
|
|
}
|
|
|
|
|
|
- private async void CopyText(object sender, RoutedEventArgs args)
|
|
|
+ private async void CopyText(object? sender, RoutedEventArgs args)
|
|
|
{
|
|
|
- await Application.Current.Clipboard.SetTextAsync(ClipboardContent.Text);
|
|
|
+ if (Application.Current!.Clipboard is { } clipboard && ClipboardContent is { } clipboardContent)
|
|
|
+ await clipboard.SetTextAsync(clipboardContent.Text ?? String.Empty);
|
|
|
}
|
|
|
|
|
|
- private async void PasteText(object sender, RoutedEventArgs args)
|
|
|
+ private async void PasteText(object? sender, RoutedEventArgs args)
|
|
|
{
|
|
|
- ClipboardContent.Text = await Application.Current.Clipboard.GetTextAsync();
|
|
|
+ if(Application.Current!.Clipboard is { } clipboard)
|
|
|
+ {
|
|
|
+ ClipboardContent.Text = await clipboard.GetTextAsync();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private async void CopyTextDataObject(object sender, RoutedEventArgs args)
|
|
|
+ private async void CopyTextDataObject(object? sender, RoutedEventArgs args)
|
|
|
{
|
|
|
- var dataObject = new DataObject();
|
|
|
- dataObject.Set(DataFormats.Text, ClipboardContent.Text ?? string.Empty);
|
|
|
- await Application.Current.Clipboard.SetDataObjectAsync(dataObject);
|
|
|
+ if (Application.Current!.Clipboard is { } clipboard)
|
|
|
+ {
|
|
|
+ var dataObject = new DataObject();
|
|
|
+ dataObject.Set(DataFormats.Text, ClipboardContent.Text ?? string.Empty);
|
|
|
+ await clipboard.SetDataObjectAsync(dataObject);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private async void PasteTextDataObject(object sender, RoutedEventArgs args)
|
|
|
+ private async void PasteTextDataObject(object? sender, RoutedEventArgs args)
|
|
|
{
|
|
|
- ClipboardContent.Text = await Application.Current.Clipboard.GetDataAsync(DataFormats.Text) as string ?? string.Empty;
|
|
|
+ if (Application.Current!.Clipboard is { } clipboard)
|
|
|
+ {
|
|
|
+ ClipboardContent.Text = await clipboard.GetDataAsync(DataFormats.Text) as string ?? string.Empty;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private async void CopyFilesDataObject(object sender, RoutedEventArgs args)
|
|
|
+ private async void CopyFilesDataObject(object? sender, RoutedEventArgs args)
|
|
|
{
|
|
|
- var files = ClipboardContent.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
- if (files.Length == 0)
|
|
|
+ if (Application.Current!.Clipboard is { } clipboard)
|
|
|
{
|
|
|
- return;
|
|
|
+ var files = (ClipboardContent.Text ?? String.Empty)
|
|
|
+ .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
+ if (files.Length == 0)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var dataObject = new DataObject();
|
|
|
+ dataObject.Set(DataFormats.FileNames, files);
|
|
|
+ await clipboard.SetDataObjectAsync(dataObject);
|
|
|
}
|
|
|
- var dataObject = new DataObject();
|
|
|
- dataObject.Set(DataFormats.FileNames, files);
|
|
|
- await Application.Current.Clipboard.SetDataObjectAsync(dataObject);
|
|
|
}
|
|
|
|
|
|
- private async void PasteFilesDataObject(object sender, RoutedEventArgs args)
|
|
|
+ private async void PasteFilesDataObject(object? sender, RoutedEventArgs args)
|
|
|
{
|
|
|
- var fiels = await Application.Current.Clipboard.GetDataAsync(DataFormats.FileNames) as IEnumerable<string>;
|
|
|
- ClipboardContent.Text = fiels != null ? string.Join(Environment.NewLine, fiels) : string.Empty;
|
|
|
+ if (Application.Current!.Clipboard is { } clipboard)
|
|
|
+ {
|
|
|
+ var fiels = await clipboard.GetDataAsync(DataFormats.FileNames) as IEnumerable<string>;
|
|
|
+ ClipboardContent.Text = fiels != null ? string.Join(Environment.NewLine, fiels) : string.Empty;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private async void GetFormats(object sender, RoutedEventArgs args)
|
|
|
{
|
|
|
- var formats = await Application.Current.Clipboard.GetFormatsAsync();
|
|
|
- ClipboardContent.Text = string.Join(Environment.NewLine, formats);
|
|
|
+ if (Application.Current!.Clipboard is { } clipboard)
|
|
|
+ {
|
|
|
+ var formats = await clipboard.GetFormatsAsync();
|
|
|
+ ClipboardContent.Text = string.Join(Environment.NewLine, formats);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private async void Clear(object sender, RoutedEventArgs args)
|
|
|
{
|
|
|
- await Application.Current.Clipboard.ClearAsync();
|
|
|
+ if (Application.Current!.Clipboard is { } clipboard)
|
|
|
+ {
|
|
|
+ await clipboard.ClearAsync();
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|