Ejemplo n.º 1
0
        private async void fieldsList_ItemClick(object sender, ItemClickEventArgs e)
        {
            SPMSchemeField field = (SPMSchemeField)e.ClickedItem;

            if (fieldsForList.membersAfter.FindIndex(f => ReferenceEquals(field, f)) < 0)
            {
                bool kept = await PromptFieldEdit(field);

                if (!kept)
                {
                    if (currScheme.Fields.Count > 1)
                    {
                        currScheme.Fields.Remove(field);
                    }
                    else
                    {
                        await this.ShowMessage("Error", "At least one field should be kept.");
                    }
                }
            }
            else
            {
                field = new SPMSchemeField();
                currScheme.Fields.Add(field);
                updateFieldsList();

                bool kept = await PromptFieldEdit(field);

                if (!kept)
                {
                    currScheme.Fields.Remove(field);
                }
            }

            updateFieldsList();
            updateIterFieldCombo();
        }
Ejemplo n.º 2
0
        private async Task <bool> PromptFieldEdit(SPMSchemeField field)
        {
            int result = 0;

            var dialog = new ContentDialog();

            dialog.Title    = "Edit Field";
            dialog.MaxWidth = ActualWidth;

            var panel = new StackPanel();

            panel.Children.Add(new TextBlock {
                Text = "Name:", TextWrapping = Windows.UI.Xaml.TextWrapping.Wrap
            });
            var nameBox = new TextBox();

            nameBox.Text = field.Name;
            panel.Children.Add(nameBox);

            panel.Children.Add(new TextBlock {
                Text = "Description:", TextWrapping = Windows.UI.Xaml.TextWrapping.Wrap
            });
            var descBox = new TextBox();

            descBox.Text = field.Description;
            panel.Children.Add(descBox);

            panel.Children.Add(new TextBlock {
                Text = "Method:", TextWrapping = Windows.UI.Xaml.TextWrapping.Wrap
            });
            var methCombo = new ComboBox();

            foreach (var v in Enum.GetValues(typeof(SPMSchemeSaltingType)))
            {
                methCombo.Items.Add(v);
            }
            int methIndex = CSHelper.IndexOfEnum(methCombo.Items, field.SaltingType);

            methCombo.SelectedIndex       = methIndex >= 0 ? methIndex : 0;
            methCombo.HorizontalAlignment = HorizontalAlignment.Stretch;
            panel.Children.Add(methCombo);

            var delBtn = new Button();

            delBtn.Click  += (o, e) => { result = 2; dialog.Hide(); };
            delBtn.Margin  = new Thickness(0, 12, 0, 0);
            delBtn.Content = new TextBlock {
                Text = "Delete", Foreground = new SolidColorBrush(Windows.UI.Colors.Red), TextWrapping = Windows.UI.Xaml.TextWrapping.Wrap
            };
            delBtn.HorizontalAlignment        = HorizontalAlignment.Stretch;
            delBtn.HorizontalContentAlignment = HorizontalAlignment.Center;
            panel.Children.Add(delBtn);

            dialog.Content             = panel;
            dialog.PrimaryButtonText   = "OK";
            dialog.PrimaryButtonClick += (o, e) => { result = 1; };

            dialog.SecondaryButtonText = "Cancel";

#if DEBUG
            dialog.Tapped += (o, e) =>
            {
                System.Diagnostics.Debug.WriteLine(String.Format("Height {0}, ActualHeight {1}, panel.Height {2}, panel.ActualHeight {3}", dialog.Height, dialog.ActualHeight, panel.Height, panel.ActualHeight));
            };
#endif

            await dialog.ShowAsync();

            if (result == 2) // delete
            {
                return(false);
            }
            else if (result == 1) // save changes
            {
                field.Name        = nameBox.Text;
                field.Description = descBox.Text;
                field.SaltingType = (SPMSchemeSaltingType)methCombo.SelectedItem;
            }
            return(true);
        }