コード例 #1
0
        private async void ToolbarItem_Clicked_Rename(object sender, EventArgs e)
        {
            var options = new ObservableCollection <EntryWithOptionViewModel.EntryWithOptionViewModelEntry>();

            if (!string.IsNullOrEmpty(Model.WordbookTitleUser) && Model.WordbookTitleUser != Model.WordbookTitleHtml)
            {
                var item = new EntryWithOptionViewModel.EntryWithOptionViewModelEntry(Model.WordbookTitleUser, Model.WordbookTitleUser);
                options.Add(item);
            }
            if (!string.IsNullOrEmpty(Model.WordbookTitleHtml))
            {
                var item = new EntryWithOptionViewModel.EntryWithOptionViewModelEntry(Model.WordbookTitleHtml, Model.WordbookTitleHtml);
                options.Add(item);
            }
            foreach (var item in RemoteStorage.GetNameSuggestions(Model.Uri))
            {
                if (item != Model.WordbookTitleUser)
                {
                    options.Add(new EntryWithOptionViewModel.EntryWithOptionViewModelEntry(item, item));
                }
            }
            if (Model == null)
            {
                return;
            }
            var vm         = (new EntryWithOptionViewModel(AppResources.WordbookRenameMessage, options, Model.WordbookTitle));
            var page       = new EntryWithOptionPage(vm);
            var waitHandle = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset);

            page.Disappearing += (s, e2) => waitHandle.Set();
            await Navigation.PushAsync(page);

            await Task.Run(() => waitHandle.WaitOne());

            var tmp = vm.GetValue <string>();

            if (tmp.Item2)
            {
                Model.WordbookTitleUser = tmp.Item1;
                await WordbooksImpressStorage.SaveLocalData();
            }
        }
コード例 #2
0
        public async Task <T> GetByActionSheet <T>(string Message, Dictionary <string, T> Options, T currentValue, bool isFirstSpecial = false, Func <object, bool> IsValid = null, WordbookImpressLibrary.ViewModels.EntryWithOptionViewModel.IValueConverter converter = null, Keyboard keyboard = null)
        {
            var    w       = new List <string>();
            string Cancel  = AppResources.AlertCancel;
            string Custom  = AppResources.AlertCustom;
            var    options = new ObservableCollection <WordbookImpressLibrary.ViewModels.EntryWithOptionViewModel.EntryWithOptionViewModelEntry>();

            foreach (var item in Options)
            {
                w.Add(item.Key);
                options.Add(new WordbookImpressLibrary.ViewModels.EntryWithOptionViewModel.EntryWithOptionViewModelEntry(item.Key, item.Value));
            }
            if (isFirstSpecial && Options.Count > 0)
            {
                options[0].IsSpecialValue = true;
            }
            w.Add(Custom);
            var result = await DisplayActionSheet(Message, Cancel, null, w.ToArray());

            if (string.IsNullOrEmpty(result) || result == Cancel)
            {
                return(currentValue);
            }
            if (result == Custom)
            {
                var vm         = (new WordbookImpressLibrary.ViewModels.EntryWithOptionViewModel(Message, options, currentValue, IsValid, converter));
                var page       = new EntryWithOptionPage(vm);
                var waitHandle = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset);
                page.Disappearing += (s, e) => waitHandle.Set();

                Keyboard keyboard_result = Keyboard.Plain;
                if (keyboard != null)
                {
                    keyboard_result = keyboard;
                }
                else if (typeof(T) == typeof(Int16) || typeof(T) == typeof(Int32) || typeof(T) == typeof(Int64))
                {
                    keyboard_result = Keyboard.Numeric;
                }
                else if (typeof(T) == typeof(float) || typeof(T) == typeof(double))
                {
                    keyboard_result = Keyboard.Numeric;
                }
                page.Keyboard = keyboard_result;

                await Navigation.PushAsync(page);

                await Task.Run(() => waitHandle.WaitOne());

                var tmp = vm.GetValue <T>();
                if (tmp.Item2)
                {
                    return(tmp.Item1);
                }
                else
                {
                    return(currentValue);
                }
            }
            else
            {
                return(Options[result]);
            }
        }