Skip to content

Commit 07c6360

Browse files
committed
Switched to using a routed command for the copy rather than an event handler.
1 parent 0109758 commit 07c6360

File tree

4 files changed

+37
-31
lines changed

4 files changed

+37
-31
lines changed

MainDemo.Wpf/App.xaml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,22 @@
6666
</materialDesign:PackIcon.Style>
6767
</materialDesign:PackIcon>
6868
</materialDesign:PopupBox.ToggleContent>
69-
<StackPanel>
70-
<Border MaxHeight="600" MaxWidth="800">
69+
<Border MaxHeight="600" MaxWidth="800">
70+
<StackPanel>
7171
<avalonEdit:TextEditor Document="{Binding Xaml, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource TextDocumentValueConverter}}"
72-
Style="{StaticResource AvalonTextEditorXamlDisplay}" />
73-
</Border>
74-
<Button
75-
Margin="0 10 0 0"
76-
Tag="{Binding Xaml, RelativeSource={RelativeSource TemplatedParent}}"
77-
Click="CopyButton_onClick"
78-
HorizontalAlignment="Right"
79-
Style="{StaticResource MaterialDesignRaisedButton}"
80-
>
81-
COPY
82-
</Button>
83-
</StackPanel>
72+
Style="{StaticResource AvalonTextEditorXamlDisplay}" />
73+
<Button
74+
Margin="0 10 0 0"
75+
Tag="{Binding Xaml, RelativeSource={RelativeSource TemplatedParent}}"
76+
HorizontalAlignment="Right"
77+
Command="Copy"
78+
CommandParameter="{Binding Xaml, RelativeSource={RelativeSource TemplatedParent}}"
79+
Content="_COPY"
80+
Style="{StaticResource MaterialDesignRaisedButton}">
81+
</Button>
82+
</StackPanel>
83+
</Border>
84+
8485
</materialDesign:PopupBox>
8586
<Grid>
8687
<AdornerDecorator>

MainDemo.Wpf/App.xaml.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Configuration;
4-
using System.Data;
5-
using System.Globalization;
6-
using System.Linq;
7-
using System.Threading;
8-
using System.Threading.Tasks;
1+
using ShowMeTheXAML;
92
using System.Windows;
10-
using System.Windows.Controls;
11-
using System.Windows.Markup;
12-
using ShowMeTheXAML;
133

144
namespace MaterialDesignColors.WpfExample
155
{
@@ -31,10 +21,5 @@ protected override void OnStartup(StartupEventArgs e)
3121

3222
base.OnStartup(e);
3323
}
34-
35-
private void CopyButton_onClick(object sender, RoutedEventArgs e) {
36-
var toBeCopied = ((Button)sender).Tag.ToString();
37-
Clipboard.SetDataObject(toBeCopied);
38-
}
3924
}
4025
}

MainDemo.Wpf/MainWindow.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
TextOptions.TextRenderingMode="Auto"
1414
Background="{DynamicResource MaterialDesignPaper}"
1515
FontFamily="{StaticResource MaterialDesignFont}" Icon="favicon.ico">
16+
<Window.CommandBindings>
17+
<CommandBinding Command="Copy" Executed="OnCopy"></CommandBinding>
18+
</Window.CommandBindings>
1619
<Window.Resources>
1720
<ResourceDictionary>
1821
<ResourceDictionary.MergedDictionaries>

MainDemo.Wpf/MainWindow.xaml.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using MaterialDesignColors.WpfExample.Domain;
1+
using System;
2+
using System.Diagnostics;
3+
using MaterialDesignColors.WpfExample.Domain;
24
using MaterialDesignThemes.Wpf;
35
using System.Threading;
46
using System.Threading.Tasks;
@@ -55,5 +57,20 @@ private async void MenuPopupButton_OnClick(object sender, RoutedEventArgs e)
5557

5658
await DialogHost.Show(sampleMessageDialog, "RootDialog");
5759
}
60+
61+
private void OnCopy(object sender, ExecutedRoutedEventArgs e)
62+
{
63+
if (e.Parameter is string stringValue)
64+
{
65+
try
66+
{
67+
Clipboard.SetText(stringValue, TextDataFormat.UnicodeText);
68+
}
69+
catch (Exception ex)
70+
{
71+
Trace.WriteLine(ex.ToString());
72+
}
73+
}
74+
}
5875
}
5976
}

0 commit comments

Comments
 (0)