#727 – Getting a List of Files from the Clipboard
January 4, 2013 1 Comment
In Windows, if you do a Copy operation on a set of files, a list of filenames will get added to the clipboard. You can get access to this list of files using the Clipboard.GetFileDropList method.
public partial class MainWindow : Window, INotifyPropertyChanged { public MainWindow() { InitializeComponent(); this.DataContext = this; } public StringCollection FileList { get; set; } private void btnPasteFileList_Click(object sender, RoutedEventArgs e) { if (Clipboard.ContainsFileDropList()) { FileList = Clipboard.GetFileDropList(); RaisePropertyChanged("FileList"); } } public event PropertyChangedEventHandler PropertyChanged; private void RaisePropertyChanged(string prop) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(prop)); } }
The XAML for this sample includes a ListBox that just binds to the FileList property.
<Grid> <Grid.RowDefinitions> <RowDefinition/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition/> </Grid.ColumnDefinitions> <ListBox ItemsSource="{Binding FileList}"/> <Button Grid.Column="1" Content="Paste File List" VerticalAlignment="Top" HorizontalAlignment="Left" Padding="10,5" Margin="10" Click="btnPasteFileList_Click"/> </Grid>
Pingback: Dew Drop – December 4, 2012 (#1,475) | Alvin Ashcraft's Morning Dew