How to validate, only allowing the user to select 1 file to read?

喜你入骨 提交于 2019-12-25 06:49:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!