J'ai un DataGrid (appelé TheGrid) que je voudrais mettre en œuvre la fonctionnalité copier et coller sur. La fonctionnalité de copie fonctionne très bien mais je ne sais pas comment implémenter coller. Ai-je juste besoin d'obtenir les données du presse-papiers et d'analyser moi-même?Coller à partir d'Excel à WPG DataGrid
Les liaisons de commande:
<Window.CommandBindings>
<CommandBinding Command="Copy" Executed="CommandBinding_Executed" CanExecute="CommandBinding_CanExecute" />
<CommandBinding Command="Paste" Executed="CommandBinding_Executed" CanExecute="CommandBinding_CanExecute" />
</Window.CommandBindings>
Les éléments de menu:
<MenuItem Header="{x:Static culture:TextResource.CopyMenuItem}" Command="Copy"/>
<MenuItem Header="{x:Static culture:TextResource.PasteMenuItem}" Command="Paste"/>
Le code derrière pour CommandBinding_Executed:
private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
if(e.Command.Equals(ApplicationCommands.Copy))
{
// This works great, wow that was easy!
ApplicationCommands.Copy.Execute(null, TheGrid);
}
else if (e.Command.Equals(ApplicationCommands.Paste))
{
//What do I do here? Is there an easy way to paste like there was for copy?
// Or do I need to grab data using Clipboard.GetData and parse it myself?
}
}
Peut-être qu'il me manque quelque chose, mais quel espace de noms est ClipboardHelper? Je ne peux pas compiler et je reçois le gribouillis rouge: -/ – KrisTrip
regarde le lien dans ma réponse –
oups, n'a pas lu assez loin ... merci :) – KrisTrip