private async Task EditPerson(ParentWithChildren parentWithChildren)
        {
            //in a real world app you would pass _people in and allow the selectable items source to dynamically change
            var editor = new RelationEditor(parentWithChildren, _people.Items.ToArray());

            //TODO: Investigate why selectable state is being held onto ny the Dialog
            await DialogHost.Show(editor, (object sender, DialogClosingEventArgs eventArgs) =>
            {
                //use the .Edit method as it is more efficient when apply multiple changes
                _relations.Edit(innerCache =>
                {
                    //extract the new relations
                    var newRelations = editor.Children
                                .Where(c => c.IsSelected).Select(selectable => new Relation(parentWithChildren.Parent, (Person)selectable))
                                .ToArray();

                    //remove old ones
                    var toRemove = innerCache
                        .Items.Where(r => r.Parent == parentWithChildren.Parent && !newRelations.Contains(r))
                        .ToArray();

                    innerCache.Remove(toRemove);
                    innerCache.AddOrUpdate(newRelations);
                });
            });
        }
        public ParentWithChildrenProxy(ParentWithChildren personWithChildren, Action <ParentWithChildren> editAction)
        {
            _personWithChildren = personWithChildren;
            var children = personWithChildren.Children;

            ChildrenNames = children.Length == 0 ? "<None>" : string.Join(", ", children.Select(p => p.Name).OrderBy(s => s));
            EditCommand   = new Command(() => editAction(personWithChildren));
        }
Exemplo n.º 3
0
        public RelationEditor(ParentWithChildren parentWithChildren, Person[] people)
        {
            Name = parentWithChildren.Parent.Name;

            Children = new ObservableCollection <SelectablePerson>
                       (
                people.Where(p => p.Name != parentWithChildren.Parent.Name)
                .Select(person => new SelectablePerson(person, parentWithChildren.Children.Contains(person)))
                       );
        }