private void btnAddIC_Click(object sender, RoutedEventArgs e) { string filename = string.Empty; Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.DefaultExt = ".png"; // Default file extension dlg.Filter = "Image Files (*.png, *.jpg, *.gif)|*.png;*.jpg;*.gif"; bool?result = dlg.ShowDialog(); if (result == true) { filename = dlg.FileName; AddIconToProject(filename); IViewModel viewModel = DataContext as IViewModel; if (viewModel != null) { FileInfo fileInfo = new FileInfo(filename); viewModel.AddIcon(fileInfo); } } }