コード例 #1
0
        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);
            }
        }
コード例 #2
0
        private void Box_LostFocus(object sender, RoutedEventArgs e)
        {
            if (this.Box == null)
            {
                return;
            }

            TextEditedEventArgs args = new TextEditedEventArgs(this.Text, this.Box.Text);

            this.TextEdited.Invoke(this, args);
            if (args.IsValid)
            {
                this.Text = this.Box.Text;
            }

            this.Container.Children.Remove(this.Box);
            this.Box = null;
            this.Block.Visibility = Windows.UI.Xaml.Visibility.Visible;
        }