WPF 给控件添加复制事作

public Window1()
{
    InitializeComponent();

    // "tb" is a TextBox
    DataObject.AddPastingHandler(tb, new DataObjectPastingEventHandler(OnPaste));
}

private void OnPaste(object sender, DataObjectPastingEventArgs e)
{
    var isText = e.SourceDataObject.GetDataPresent(System.Windows.DataFormats.Text, true);
    if (!isText) return;

    var text = e.SourceDataObject.GetData(DataFormats.Text) as string;
    
}

  

posted @ 2013-01-05 17:19  li-peng  阅读(949)  评论(0编辑  收藏  举报