public void TreeViewCopyCommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e) { TreeView treeView = (TreeView)sender; SimplePropertyModel simplePropertyModel = treeView.SelectedItem as SimplePropertyModel; e.CanExecute = simplePropertyModel != null; }
public void TreeViewCopyCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e) { TreeView treeView = (TreeView)sender; PropertyModel propertyModel = treeView.SelectedItem as PropertyModel; SimplePropertyModel simplePropertyModel = propertyModel as SimplePropertyModel; string text = null; if (simplePropertyModel != null) { //TODO: This is bad to do? text = string.Format("{0}: {1}", simplePropertyModel.PropertyName, simplePropertyModel.PropertyValue); } else if (propertyModel != null) { text = propertyModel.PropertyName; } else { throw new ArgumentException("sender"); } Clipboard.SetText(text); }