private void Delete_Click(object sender, RoutedEventArgs e) { Resource item = this.SelectedBlock.Tag as Resource; this.SelectedBlock = null; UIHelper.ShowWarningDialogAsync(t => { if (Database.Current.DeleteResource(this.ResType, item.FullName)) { this.Items.Remove(item); if (item.IsAvailable) { string fileName = item.FullName; if (this.ResType == ResourceType.Songs) { fileName += ".mp3"; } AsyncHelper.RunSync(() => Library.DeleteResourceAsync(this.ResType, fileName)); } } else { UIHelper.ShowMessageDialogAsync("Ресурс " + item.FullName + " используется в дневнике и не может быть удалён"); } }); }
private void SelectedBlock_TextEdited(object sender, TextEditedEventArgs e) { try { EditableTextBlock block = sender as EditableTextBlock; block.TextEdited -= this.SelectedBlock_TextEdited; if (e.OldValue == e.NewValue) { return; } if (String.IsNullOrWhiteSpace(e.NewValue)) { throw new FormatException("Имя не заполнено"); } if (this.ResType != ResourceType.Tags && (e.NewValue.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0 || e.NewValue.Last() == '.')) { throw new FormatException("Недопустимое имя файла"); } if (!Database.Current.UpdateResource(this.ResType, e.OldValue, e.NewValue)) { throw new ArgumentException("Ресурс с именем " + e.NewValue + " уже существует. Выберите другое название"); } if (this.ResType != ResourceType.Tags) { string oldName = e.OldValue; string newName = e.NewValue; //Названия песен хранятся в базе данных без расширения if (this.ResType == ResourceType.Songs) { oldName += ".mp3"; newName += ".mp3"; } AsyncHelper.RunSync(() => this.RenameIfExistAsync(oldName, newName, this.ResType)); } //Так как не работает двусторонняя привязка (block.Tag as Resource).FullName = e.NewValue; } catch (Exception ex) { e.IsValid = false; UIHelper.ShowMessageDialogAsync(ex.Message); } }
private async void DeleteFile_Click(object sender, RoutedEventArgs e) { Resource item = this.SelectedBlock.Tag as Resource; this.SelectedBlock = null; if (item.IsAvailable) { string fileName = item.FullName; if (this.ResType == ResourceType.Songs) { fileName += ".mp3"; } await Library.DeleteResourceAsync(this.ResType, fileName); item.File = null; int index = this.Items.IndexOf(item); this.Items.RemoveAt(index); this.Items.Insert(index, item); } }
private void ContextMenu_ClosedOnEditing(object sender, object e) { (sender as FlyoutBase).Closed -= this.ContextMenu_ClosedOnEditing; this.SelectedBlock.Edit(); this.SelectedBlock = null; }
private void Item_RightTapped(object sender, RightTappedRoutedEventArgs e) { this.SelectedBlock = (sender as Grid).Children[0] as EditableTextBlock; this.ContextMenu.ShowAt((FrameworkElement)sender); }