Can I send the clipboard as a command parameter?

Using MVVM I have a ViewModel that implements commands. I would like to get the contents of the clipboard as a parameter and do something with it.

XAML:

    <Button Command="{Binding Path=ClipBoardAction}" 
            CommandParameter="{Binding SomeAwesomeCodeHereToPassCurrentClipboard}" />

WITH#:

private void ClipBoardAction(object parameter) {
    //parameter is clipboard OR CLIPBOARD DATA like string[]
 }

Is it possible? If so, what am I getting attached to in XAML?

EDIT : work so far - just connect the button to the Click event and paste the code behind the glue.

    private void Button_Click(object sender, RoutedEventArgs e) {
        //manually send command to object
        string[] clipboard = Clipboard.GetText().Split(new Char[] { '\n' });
        var but = sender as Button;
        var viewModel = (FooViewModel)but.DataContext;
        if (viewModel.ClipBoardAction.CanExecute(null)){
            viewModel.ClipBoardAction.Execute(clipboard);
        }
    }
+4
source share
1 answer

Since the Clipboard class provides clipboard data as methods, not properties, and binding can only be done using properties, you cannot do that.

Edit

You can crack the problem by running your own converter , but I do not think this is very worthy:

public class ClipboardConverter : IValueConverter {
    public object Convert(object value, Type targetType, object parameter, 
                  System.Globalization.CultureInfo culture) {
        return Clipboard.GetData(value as string);
    }
    public object ConvertBack(object value, Type targetType, object parameter, 
                  System.Globalization.CultureInfo culture) {
        throw new NotImplementedException();
    }
}
+1
source

All Articles