I have a ListView, and I am trying to eliminates duplicates.
public Command? SendCommand { get; set; }
public Command? ValidateTextCommand { get; set; }
public Command? ValidateNumberCommand { get; set; }
public Command? SearchPictureCommand { get; set; }
public Command<Window>? DragWindowCommand { get; set; }
public Building? Building { get; set; }
public File? File { get; set; }
public string? SeletedItem { get; set; }
public PrpertiesWindowViewModel() {
Building = new Building();
SendCommand = new Command(SendToServer);
ValidateTextCommand = new Command(ValidateTextAction);
ValidateNumberCommand = new Command(ValidateNumberAction);
SearchPictureCommand = new Command(SearchPictureAction);
DragWindowCommand = new Command<Window>(DragWindowAction);
}
private void DragWindowAction(Window obj) {
if (obj != null) {
obj.DragMove();
}
}
private void SearchPictureAction() {
var dialog = new OpenFileDialog {
Filter = "Image files (*.png;*.jpeg)|*.png;*.jpeg;",
CheckPathExists = true,
Multiselect = true,
InitialDirectory = GetFolderPath(SpecialFolder.MyPictures)
};
if (dialog.ShowDialog() == true) {
if (Building?.FileNames != null) {
foreach (var item in dialog.FileNames) {
File = new File { FileName = Path.GetFileName(item), FullPath = Path.GetFullPath(item) };
if (!Building.FileNames.Contains(File)) {
Building.FileNames.Add(File);
}
}
}
}
}
If a file, does not exist in my collection, add it.
class
public string? Name { get; set; }
public string? Desc { get; set; }
public string? Address { get; set; }
public string? Rooms { get; set; }
public ObservableCollection<File>? FileNames { get; set; }
public Building() {
FileNames = new ObservableCollection<File>();
}
}
[AddINotifyPropertyChangedInterface]
public class File {
public string? FullPath { get; set; }
public string? FileName { get; set; }
}
}