Communication with clipboard in silverlight4beta

Source: Internet
Author: User

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 ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.