Coller d'Excel à WPF DataGrid
J'ai un DataGrid (appelé TheGrid) que je voudrais mettre en œuvre fonctionnalité copier-coller. La fonctionnalité de copie fonctionne très bien mais je ne sais pas comment la mettre la pâte. Dois-je tout simplement besoin d'obtenir les données à partir du presse-papiers et analyser moi-même?
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-behind 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?
}
}
source d'informationauteur KrisTrip
Vous devez vous connecter pour publier un commentaire.
Il n'est pas facile à faire
Vous devez analyser les données du presse-papiers avec
ClipboardHelper
jetez un oeil à cette question