示例#1
0
		protected override void Init ()
		{
			var layout = new StackLayout ();
			var button = new Button { Text = "Click" };
			var tablesection = new TableSection { Title = "Switches" };
			var tableview = new TableView { Intent = TableIntent.Form, Root = new TableRoot { tablesection } };
			var viewcell1 = new ViewCell {
				View = new StackLayout {
					HorizontalOptions = LayoutOptions.FillAndExpand,
					Orientation = StackOrientation.Horizontal,
					Children = {
						new Label { Text = "Switch 1", HorizontalOptions = LayoutOptions.StartAndExpand },
						new Switch { AutomationId = "switch1", HorizontalOptions = LayoutOptions.End, IsToggled = true }
					}
				}
			};
			var viewcell2 = new ViewCell {
				View = new StackLayout {
					HorizontalOptions = LayoutOptions.FillAndExpand,
					Orientation = StackOrientation.Horizontal,
					Children = {
						new Label { Text = "Switch 2", HorizontalOptions = LayoutOptions.StartAndExpand },
						new Switch { AutomationId = "switch2", HorizontalOptions = LayoutOptions.End, IsToggled = true }
					}
				}
			};
			Label label = new Label { Text = "Switch 3", HorizontalOptions = LayoutOptions.StartAndExpand };
			Switch switchie = new Switch { AutomationId = "switch3", HorizontalOptions = LayoutOptions.End, IsToggled = true, IsEnabled = false };
			switchie.Toggled += (sender, e) => {
				label.Text = "FAIL";
			};
			var viewcell3 = new ViewCell {
				View = new StackLayout {
					HorizontalOptions = LayoutOptions.FillAndExpand,
					Orientation = StackOrientation.Horizontal,
					Children = {
						label,
						switchie,
					}
				}
			};

			tablesection.Add (viewcell1);
			tablesection.Add (viewcell2);
			tablesection.Add (viewcell3);

			button.Clicked += (sender, e) => {
				if (_removed)
					tablesection.Insert (1, viewcell2);
				else
					tablesection.Remove (viewcell2);

				_removed = !_removed;
			};

			layout.Children.Add (button);
			layout.Children.Add (tableview);

			Content = layout;
		}
示例#2
0
        private void RemoveCell(TableSection section, ITableCellViewModel cell)
        {
            var cellView = _tableCellViewModelMap[cell];

            _tableCellViewModelMap.Remove(cell);
            _tableCellReverseViewModelMap.Remove(cellView);
            section.Remove(cellView);
        }
示例#3
0
		public void Remove ()
		{
			var section = new TableSection ();
			TextCell first;
			section.Add (first = new TextCell { Text = "Text" });
			section.Add (new TextCell { Text = "Text" });

			var result = section.Remove (first);
			Assert.True (result);
			Assert.That (section, Has.No.Contains (first));
		}
示例#4
0
        public void Remove()
        {
            var      section = new TableSection();
            TextCell first;

            section.Add(first = new TextCell {
                Text = "Text"
            });
            section.Add(new TextCell {
                Text = "Text"
            });

            var result = section.Remove(first);

            Assert.True(result);
            Assert.That(section, Has.No.Contains(first));
        }
示例#5
0
 private void buildView()
 {
     Logger($"build view : {datas.Count} ele");
     foreach (var c in sectdatas)
     {
         c.Tapped -= OnCellTapped;
         sect?.Remove(c);
     }
     sectdatas.Clear();
     foreach (var d in datas)
     {
         var cell = new SelectCell(d.Text, d.IsSelected);
         cell.Tapped += OnCellTapped;
         sect?.Add(cell);
         sectdatas.Add(cell);
     }
 }
示例#6
0
        private static void ToggleViewCellCollapsedState(Cell cell, bool isVisible)
        {
            var          table     = (TableView)cell.Parent;
            TableSection container = FindContainingTableSection(table, cell);

            if (container != null)
            {
                if (!isVisible)
                {
                    // remove the cell from the section
                    container.Remove(cell);

                    // remove the section from the table if it's empty
                    if (container.Count == 0)
                    {
                        table.Root.Remove(container);
                    }
                }
            }
        }
示例#7
0
文件: Helpers.cs 项目: aidmsu/mobile
        public static FormEntryCell MakeUriCell(string value, UriMatchType?match, TableSection urisSection, Page page)
        {
            var label = string.Format(AppResources.URIPosition, urisSection.Count);
            var cell  = new FormEntryCell(label, entryKeyboard: Keyboard.Url);

            cell.Entry.Text = value;
            cell.Entry.DisableAutocapitalize = true;
            cell.Entry.Autocorrect           = false;
            cell.MetaData = new Dictionary <string, object> {
                ["match"] = match
            };

            var deleteAction = new MenuItem {
                Text = AppResources.Remove, IsDestructive = true
            };

            deleteAction.Clicked += (sender, e) =>
            {
                if (urisSection.Contains(cell))
                {
                    urisSection.Remove(cell);
                    if (cell is FormEntryCell feCell)
                    {
                        feCell.Dispose();
                    }
                    cell = null;

                    for (int i = 0; i < urisSection.Count; i++)
                    {
                        if (urisSection[i] is FormEntryCell uriCell)
                        {
                            uriCell.Label.Text = string.Format(AppResources.URIPosition, i + 1);
                        }
                    }
                }
            };

            var optionsAction = new MenuItem {
                Text = AppResources.Options
            };

            optionsAction.Clicked += async(sender, e) =>
            {
                var options = UriMatchOptionsMap.Select(v => v.Value).ToList();
                options.Insert(0, AppResources.Default);
                var exactingMatchVal = cell.MetaData["match"] as UriMatchType?;

                var matchIndex = exactingMatchVal.HasValue ?
                                 Array.IndexOf(UriMatchOptionsMap.Keys.ToArray(), exactingMatchVal) + 1 : 0;
                options[matchIndex] = $"✓ {options[matchIndex]}";

                var optionsArr = options.ToArray();
                var val        = await page.DisplayActionSheet(AppResources.URIMatchDetection, AppResources.Cancel,
                                                               null, options.ToArray());

                UriMatchType?selectedVal = null;
                if (val == AppResources.Cancel)
                {
                    selectedVal = exactingMatchVal;
                }
                else if (val != AppResources.Default)
                {
                    selectedVal = UriMatchOptionsMap.ElementAt(Array.IndexOf(optionsArr, val) - 1).Key;
                }
                cell.MetaData["match"] = selectedVal;
            };

            cell.ContextActions.Add(optionsAction);
            cell.ContextActions.Add(deleteAction);
            return(cell);
        }
示例#8
0
文件: Helpers.cs 项目: aidmsu/mobile
        public static Cell MakeFieldCell(FieldType type, string label, string value, TableSection fieldsSection)
        {
            Cell cell;

            switch (type)
            {
            case FieldType.Text:
            case FieldType.Hidden:
                var hidden        = type == FieldType.Hidden;
                var textFieldCell = new FormEntryCell(label, isPassword: hidden,
                                                      button1: hidden ? "eye.png" : null);
                textFieldCell.Entry.Text = value;
                textFieldCell.Entry.DisableAutocapitalize = true;
                textFieldCell.Entry.Autocorrect           = false;

                if (hidden)
                {
                    textFieldCell.Entry.FontFamily = Helpers.OnPlatform(
                        iOS: "Menlo-Regular", Android: "monospace", Windows: "Courier");
                    textFieldCell.Button1.Command = new Command(() =>
                    {
                        textFieldCell.Entry.InvokeToggleIsPassword();
                        textFieldCell.Button1.Image =
                            "eye" + (!textFieldCell.Entry.IsPasswordFromToggled ? "_slash" : string.Empty) + ".png";
                    });
                }
                cell = textFieldCell;
                break;

            case FieldType.Boolean:
                var switchFieldCell = new ExtendedSwitchCell
                {
                    Text = label,
                    On   = value == "true"
                };
                cell = switchFieldCell;
                break;

            default:
                cell = null;
                break;
            }

            if (cell != null)
            {
                var deleteAction = new MenuItem {
                    Text = AppResources.Remove, IsDestructive = true
                };
                deleteAction.Clicked += (sender, e) =>
                {
                    if (fieldsSection.Contains(cell))
                    {
                        fieldsSection.Remove(cell);
                    }

                    if (cell is FormEntryCell feCell)
                    {
                        feCell.Dispose();
                    }
                    cell = null;
                };

                var editNameAction = new MenuItem {
                    Text = AppResources.Edit
                };
                editNameAction.Clicked += async(sender, e) =>
                {
                    string existingLabel = null;
                    var    feCell        = cell as FormEntryCell;
                    var    esCell        = cell as ExtendedSwitchCell;
                    if (feCell != null)
                    {
                        existingLabel = feCell.Label.Text;
                    }
                    else if (esCell != null)
                    {
                        existingLabel = esCell.Text;
                    }

                    var daService = Resolver.Resolve <IDeviceActionService>();
                    var editLabel = await daService.DisplayPromptAync(AppResources.CustomFieldName,
                                                                      null, existingLabel);

                    if (editLabel != null)
                    {
                        if (feCell != null)
                        {
                            feCell.Label.Text = editLabel;
                        }
                        else if (esCell != null)
                        {
                            esCell.Text = editLabel;
                        }
                    }
                };

                cell.ContextActions.Add(editNameAction);
                cell.ContextActions.Add(deleteAction);
            }

            return(cell);
        }
示例#9
0
        public static FormEntryCell MakeUriCell(string value, UriMatchType?match, TableSection urisSection, Page page)
        {
            var label = string.Format(AppResources.URIPosition, urisSection.Count);
            var cell  = new FormEntryCell(label, entryKeyboard: Keyboard.Url, button1: "cog_alt.png");

            cell.Entry.Text = value;
            cell.Entry.DisableAutocapitalize = true;
            cell.Entry.Autocorrect           = false;
            cell.MetaData = new Dictionary <string, object> {
                ["match"] = match
            };

            cell.Button1.Command = new Command(async() =>
            {
                var optionsVal = await page.DisplayActionSheet(AppResources.Options, AppResources.Cancel,
                                                               null, AppResources.MatchDetection, AppResources.Remove);

                if (optionsVal == AppResources.MatchDetection)
                {
                    var options = UriMatchOptionsMap.Select(v => v.Value).ToList();
                    options.Insert(0, AppResources.Default);
                    var exactingMatchVal = cell.MetaData["match"] as UriMatchType?;

                    var matchIndex = exactingMatchVal.HasValue ?
                                     Array.IndexOf(UriMatchOptionsMap.Keys.ToArray(), exactingMatchVal) + 1 : 0;
                    options[matchIndex] = $"✓ {options[matchIndex]}";

                    var optionsArr = options.ToArray();
                    var val        = await page.DisplayActionSheet(AppResources.URIMatchDetection, AppResources.Cancel,
                                                                   null, options.ToArray());

                    UriMatchType?selectedVal = null;
                    if (val == null || val == AppResources.Cancel)
                    {
                        selectedVal = exactingMatchVal;
                    }
                    else if (val.Replace("✓ ", string.Empty) != AppResources.Default)
                    {
                        selectedVal = UriMatchOptionsMap.ElementAt(Array.IndexOf(optionsArr, val) - 1).Key;
                    }
                    cell.MetaData["match"] = selectedVal;
                }
                else if (optionsVal == AppResources.Remove)
                {
                    if (urisSection.Contains(cell))
                    {
                        urisSection.Remove(cell);
                        if (cell is FormEntryCell feCell)
                        {
                            feCell.Dispose();
                        }
                        cell = null;

                        for (int i = 0; i < urisSection.Count; i++)
                        {
                            if (urisSection[i] is FormEntryCell uriCell)
                            {
                                uriCell.Label.Text = string.Format(AppResources.URIPosition, i + 1);
                            }
                        }
                    }
                }
            });

            return(cell);
        }
示例#10
0
        public static Cell MakeFieldCell(FieldType type, string label, string value,
                                         TableSection fieldsSection, Page page)
        {
            Cell           cell;
            FormEntryCell  feCell = null;
            FormSwitchCell fsCell = null;

            switch (type)
            {
            case FieldType.Text:
            case FieldType.Hidden:
                var hidden = type == FieldType.Hidden;
                cell = feCell = new FormEntryCell(label, isPassword: hidden,
                                                  button1: hidden ? "eye.png" : "cog_alt.png", button2: hidden ? "cog_alt.png" : null);
                feCell.Entry.Text = value;
                feCell.Entry.DisableAutocapitalize = true;
                feCell.Entry.Autocorrect           = false;

                if (hidden)
                {
                    feCell.Entry.FontFamily = OnPlatform(iOS: "Menlo-Regular", Android: "monospace",
                                                         Windows: "Courier");
                    feCell.Button1.Command = new Command(() =>
                    {
                        feCell.Entry.InvokeToggleIsPassword();
                        feCell.Button1.Image = "eye" +
                                               (!feCell.Entry.IsPasswordFromToggled ? "_slash" : string.Empty) + ".png";
                    });
                }
                break;

            case FieldType.Boolean:
                cell = fsCell = new FormSwitchCell(label, "cog_alt.png");
                fsCell.Switch.IsToggled = value == "true";
                break;

            default:
                cell = null;
                break;
            }

            if (cell != null)
            {
                var optionsButton = feCell != null ? feCell.Button2 ?? feCell.Button1 : fsCell.Button1;
                optionsButton.Command = new Command(async() =>
                {
                    var optionsVal = await page.DisplayActionSheet(AppResources.Options, AppResources.Cancel,
                                                                   null, AppResources.Edit, AppResources.Remove);
                    if (optionsVal == AppResources.Remove)
                    {
                        if (fieldsSection.Contains(cell))
                        {
                            fieldsSection.Remove(cell);
                        }

                        if (feCell != null)
                        {
                            feCell.Dispose();
                        }
                        cell   = null;
                        feCell = null;
                        fsCell = null;
                    }
                    else if (optionsVal == AppResources.Edit)
                    {
                        var existingLabel = feCell?.Label.Text ?? fsCell?.Label.Text;
                        var daService     = Resolver.Resolve <IDeviceActionService>();
                        var editLabel     = await daService.DisplayPromptAync(AppResources.CustomFieldName,
                                                                              null, existingLabel);
                        if (editLabel != null)
                        {
                            if (feCell != null)
                            {
                                feCell.Label.Text = editLabel;
                            }
                            else if (fsCell != null)
                            {
                                fsCell.Label.Text = editLabel;
                            }
                        }
                    }
                });
            }

            return(cell);
        }
示例#11
0
        protected override void Init()
        {
            var layout = new StackLayout();
            var button = new Button {
                Text = "Click"
            };
            var tablesection = new TableSection {
                Title = "Switches"
            };
            var tableview = new TableView {
                Intent = TableIntent.Form, Root = new TableRoot {
                    tablesection
                }
            };
            var viewcell1 = new ViewCell
            {
                View = new StackLayout
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    Orientation       = StackOrientation.Horizontal,
                    Children          =
                    {
                        new Label  {
                            Text = "Switch 1", HorizontalOptions = LayoutOptions.StartAndExpand
                        },
                        new Switch {
                            AutomationId = "switch1", HorizontalOptions = LayoutOptions.End, IsToggled = true
                        }
                    }
                }
            };
            var viewcell2 = new ViewCell
            {
                View = new StackLayout
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    Orientation       = StackOrientation.Horizontal,
                    Children          =
                    {
                        new Label  {
                            Text = "Switch 2", HorizontalOptions = LayoutOptions.StartAndExpand
                        },
                        new Switch {
                            AutomationId = "switch2", HorizontalOptions = LayoutOptions.End, IsToggled = true
                        }
                    }
                }
            };
            Label label = new Label {
                Text = "Switch 3", HorizontalOptions = LayoutOptions.StartAndExpand
            };
            Switch switchie = new Switch {
                AutomationId = "switch3", HorizontalOptions = LayoutOptions.End, IsToggled = true, IsEnabled = false
            };

            switchie.Toggled += (sender, e) =>
            {
                label.Text = "FAIL";
            };
            var viewcell3 = new ViewCell
            {
                View = new StackLayout
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    Orientation       = StackOrientation.Horizontal,
                    Children          =
                    {
                        label,
                        switchie,
                    }
                }
            };

            tablesection.Add(viewcell1);
            tablesection.Add(viewcell2);
            tablesection.Add(viewcell3);

            button.Clicked += (sender, e) =>
            {
                if (_removed)
                {
                    tablesection.Insert(1, viewcell2);
                }
                else
                {
                    tablesection.Remove(viewcell2);
                }

                _removed = !_removed;
            };

            layout.Children.Add(button);
            layout.Children.Add(tableview);

            Content = layout;
        }