public static CheckablePatternDataViewModel ToCheckable(this PatternDataViewModel source, ItemState state) { return(new CheckablePatternDataViewModel(source, state)); }
public CheckablePatternDataViewModel(PatternDataViewModel viewModel) : base(viewModel.Name, viewModel.PatternType, viewModel.Data) { Id = viewModel.Id; }
public CheckablePatternDataViewModel(PatternDataViewModel viewModel, ItemState state) : this(viewModel) { State = state; }
private void AddPatterns() { OpenFileDialog fileDialog = new OpenFileDialog() { CheckFileExists = true, CheckPathExists = true, Multiselect = true, Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg" }; Func <string, bool> isValidFile = file => { string[] extensions = { ".png", ".jpeg", ".jpg" }; string ext = Path.GetExtension(file); return(extensions.Contains(ext)); }; fileDialog.FileOk += (sender, args) => { if (!fileDialog.FileNames.All(isValidFile)) { args.Cancel = true; } }; bool?dialogResult = fileDialog.ShowDialog(); if (dialogResult.HasValue && dialogResult.Value) { try { Stream[] files = fileDialog.OpenFiles(); for (int i = 0; i < fileDialog.FileNames.Length; i++) { string filePath = fileDialog.FileNames[i]; Stream file = files[i]; byte[] fileData = null; using (var stream = new MemoryStream()) { file.CopyTo(stream); fileData = stream.ToArray(); } CheckablePatternDataViewModel viewModel = new PatternDataViewModel(Path.GetFileName(filePath), Pattern.PatternType, fileData) .ToCheckable(ItemState.Added); Children.Add(viewModel); } } catch (Exception ex) { } CheckItem(); } }