问题
Below are the codes to allow the user to read a File. How to allow the user to select only 1 file to read?
private void button3_Click(object sender, RoutedEventArgs e)
{
ViewDiskModel model = this.ContentPanel.DataContext as ViewDiskModel;
if (model.Files.Any(file => file.IsChecked))
{
model.ReadSelectedFiles.Execute(null);
NavigationService.Navigate(new Uri("/AnswerQuestionPage.xaml", UriKind.Relative));
}
else
if ((model.Files.Any(file => file.IsChecked)) > 1)
{
MessageBox.Show("Please Select only 1 File.");
}
}
回答1:
Replace model.Files.Any(file => file.IsChecked)
with model.Files.Count(file => file.IsChecked) == 1
.
来源:https://stackoverflow.com/questions/6577693/how-to-validate-only-allowing-the-user-to-select-1-file-to-read