private void ButRename_Click(object sender, RoutedEventArgs e) { Peripheral p = (Peripheral)((FrameworkElement)sender).DataContext; StringDialog wndPair = new StringDialog("Renaming", "Enter a new name for the device"); if (wndPair.ShowDialog().GetValueOrDefault(false)) { if (!string.IsNullOrWhiteSpace(wndPair.Result)) { _viewModel.Rename(p.Id, wndPair.Result); } } }