I mentioned in my previous article "support by right-clicking silverlight4beta" That sl4 supports right-clicking. Although context menu controls are not provided, it is not difficult to implement them. The most common operation of context menus is to copy, paste, and cut the functions of this class. Today we will talk about another simple new feature of silverlight4beta: communication with the clipboard (in earlier SL versions, because there is no built-in support for communication with the clipboard, we can only implement communication between the SL and the clipboard by calling JS)
Yes, sl4 does support clipboard, but its functionality is poor.
All functions of the clipboard are under the system. Windows. Clipboard class. Let's take a look at its member definitions:
Public static bool containstext (); whether the Clipboard contains the public static string gettext ();
Public static void settext (string text); set the text content of the clipboard
There are only three methods. The number of members is really poor, and the functions are actually too simple. As mentioned above, sl4 only supports processing text information in the clipboard, so you can ignore the pictures and other multimedia information.
Next we will give a simple example. The code is very simple and will not be explained in detail.
The XAML is as follows:
<Grid X: Name = "layoutroot" background = "white"> <stackpanel orientation = "horizontal" Height = "40"> <textbox acceptsreturn = "true" X: name = "txttext" width = "150"/> <button content = "copy" Click = "copy"/> <button content = "Paste" Click = "Paste"/> </stackpanel> </GRID>
C # The Code is as follows:
public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); } private void Paste(object sender, RoutedEventArgs e) { if (Clipboard.ContainsText()) txtText.Text = Clipboard.GetText(); } private void Copy(object sender, RoutedEventArgs e) { if (!string.IsNullOrEmpty(txtText.Text.Trim())) Clipboard.SetText(txtText.Text); }}
The running effect is as follows:
In addition, when the SL client communicates with the clipboard for the first time, the user must agree
For a detailed explanation of security, see my blog post about how to operate cameras/microphones in silverlight4beta.
OK, have fun ~