Esempio n. 1
1
        public void Moving_Items_Should_Raise_CollectionChanged()
        {
            var target = new AvaloniaList<int>(new[] { 1, 2, 3 });
            var raised = false;

            target.CollectionChanged += (s, e) =>
            {
                Assert.Equal(target, s);
                Assert.Equal(NotifyCollectionChangedAction.Move, e.Action);
                Assert.Equal(new[] { 2, 3 }, e.OldItems.Cast<int>());
                Assert.Equal(new[] { 2, 3 }, e.NewItems.Cast<int>());
                Assert.Equal(1, e.OldStartingIndex);
                Assert.Equal(0, e.NewStartingIndex);

                raised = true;
            };

            target.MoveRange(1, 2, 0);

            Assert.True(raised);
        }
Esempio n. 2
0
        public void Items_Passed_To_Constructor_Should_Appear_In_List()
        {
            var items = new[] { 1, 2, 3 };
            var target = new AvaloniaList<int>(items);

            Assert.Equal(items, target);
        }
Esempio n. 3
0
        public void MoveRange_Should_Update_Collection()
        {
            var target = new AvaloniaList<int>(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });

            target.MoveRange(4, 3, 0);

            Assert.Equal(new[] { 5, 6, 7, 1, 2, 3, 4, 8, 9, 10 }, target);
        }
Esempio n. 4
0
        public void MoveRange_Can_Move_To_End()
        {
            var target = new AvaloniaList<int>(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });

            target.MoveRange(0, 5, 10);

            Assert.Equal(new[] { 6, 7, 8, 9, 10, 1, 2, 3, 4, 5 }, target);
        }
Esempio n. 5
0
        public void Move_Should_Update_Collection()
        {
            var target = new AvaloniaList<int>(new[] { 1, 2, 3 });

            target.Move(2, 0);

            Assert.Equal(new[] { 3, 1, 2 }, target);
        }
Esempio n. 6
0
        public void Control_Item_Should_Be_Removed_From_Logical_Children_Before_ApplyTemplate()
        {
            var target = new ItemsControl();
            var child = new Control();
            var items = new AvaloniaList<Control>(child);

            target.Template = GetTemplate();
            target.Items = items;
            items.RemoveAt(0);

            Assert.Null(child.Parent);
            Assert.Null(child.GetLogicalParent());
            Assert.Empty(target.GetLogicalChildren());
        }
        public void First_Item_Should_Be_Selected_When_Added()
        {
            var items = new AvaloniaList<string>();
            var target = new TestSelector
            {
                Items = items,
                Template = Template(),
            };

            target.ApplyTemplate();
            items.Add("foo");

            Assert.Equal(0, target.SelectedIndex);
            Assert.Equal("foo", target.SelectedItem);
        }
        public void Should_Remove_Containers()
        {
            var items = new AvaloniaList<string>(new[] { "foo", "bar" });
            var target = new ItemsPresenter
            {
                Items = items,
            };

            target.ApplyTemplate();
            items.RemoveAt(0);

            Assert.Equal(1, target.Panel.Children.Count);
            Assert.Equal("bar", ((ContentPresenter)target.Panel.Children[0]).Content);
            Assert.Equal("bar", ((ContentPresenter)target.ItemContainerGenerator.ContainerFromIndex(0)).Content);
        }
        public void Item_Should_Be_Selected_When_Selection_Removed()
        {
            var items = new AvaloniaList<string>(new[] { "foo", "bar", "baz", "qux" });

            var target = new TestSelector
            {
                Items = items,
                Template = Template(),
            };

            target.ApplyTemplate();
            target.SelectedIndex = 2;
            items.RemoveAt(2);

            Assert.Equal(2, target.SelectedIndex);
            Assert.Equal("qux", target.SelectedItem);
        }
        public void Selection_Should_Be_Cleared_When_No_Items_Left()
        {
            var items = new AvaloniaList<string>(new[] { "foo", "bar" });

            var target = new TestSelector
            {
                Items = items,
                Template = Template(),
            };

            target.ApplyTemplate();
            target.SelectedIndex = 1;
            items.RemoveAt(1);
            items.RemoveAt(0);

            Assert.Equal(-1, target.SelectedIndex);
            Assert.Null(target.SelectedItem);
        }
Esempio n. 11
0
        public void Inserting_Items_Should_Raise_CollectionChanged()
        {
            var target = new AvaloniaList <int>(new[] { 1, 2 });
            var raised = false;

            target.CollectionChanged += (s, e) =>
            {
                Assert.Equal(target, s);
                Assert.Equal(NotifyCollectionChangedAction.Add, e.Action);
                Assert.Equal(new[] { 3, 4 }, e.NewItems.Cast <int>());
                Assert.Equal(1, e.NewStartingIndex);

                raised = true;
            };

            target.InsertRange(1, new[] { 3, 4 });

            Assert.True(raised);
        }
Esempio n. 12
0
        public void Removing_Item_Should_Raise_CollectionChanged()
        {
            var target = new AvaloniaList <int>(new[] { 1, 2, 3 });
            var raised = false;

            target.CollectionChanged += (s, e) =>
            {
                Assert.Equal(target, s);
                Assert.Equal(NotifyCollectionChangedAction.Remove, e.Action);
                Assert.Equal(new[] { 3 }, e.OldItems.Cast <int>());
                Assert.Equal(2, e.OldStartingIndex);

                raised = true;
            };

            target.Remove(3);

            Assert.True(raised);
        }
Esempio n. 13
0
        public VisualTreeNode(IVisual visual, TreeNode parent)
            : base(visual, parent)
        {
            var host = visual as IVisualTreeHost;

            if (host?.Root == null)
            {
                Children = visual.VisualChildren.CreateDerivedList(x => new VisualTreeNode(x, this));
            }
            else
            {
                Children = new AvaloniaList <VisualTreeNode>(new[] { new VisualTreeNode(host.Root, this) });
            }

            if ((Visual is IStyleable styleable))
            {
                IsInTemplate = styleable.TemplatedParent != null;
            }
        }
Esempio n. 14
0
 private void ResizeItems(int count)
 {
     if (Items == null)
     {
         var items = Enumerable.Range(0, count)
                     .Select(x => new ItemViewModel(x));
         Items = new AvaloniaList <ItemViewModel>(items);
     }
     else if (count > Items.Count)
     {
         var items = Enumerable.Range(Items.Count, count - Items.Count)
                     .Select(x => new ItemViewModel(x));
         Items.AddRange(items);
     }
     else if (count < Items.Count)
     {
         Items.RemoveRange(count, Items.Count - count);
     }
 }
Esempio n. 15
0
        public void Should_Handle_Duplicate_Items()
        {
            var items = new AvaloniaList <int>(new[] { 1, 2, 1 });

            var target = new ItemsPresenter
            {
                Items = items,
            };

            target.ApplyTemplate();
            items.RemoveAt(2);

            var numbers = target.Panel.Children
                          .OfType <ContentPresenter>()
                          .Select(x => x.Content)
                          .Cast <int>();

            Assert.Equal(new[] { 1, 2 }, numbers);
        }
Esempio n. 16
0
        public void Can_Decrease_Number_Of_Materialized_Items_By_Removing_From_Source_Collection()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var items  = new AvaloniaList <string>(Enumerable.Range(0, 20).Select(x => $"Item {x}"));
                var target = new ListBox
                {
                    Template     = ListBoxTemplate(),
                    Items        = items,
                    ItemTemplate = new FuncDataTemplate <string>((x, _) => new TextBlock {
                        Height = 10
                    })
                };

                Prepare(target);
                target.Scroll.Offset = new Vector(0, 1);

                items.RemoveRange(0, 11);
            }
        }
Esempio n. 17
0
        public void Removing_Items_Should_Fire_LogicalChildren_CollectionChanged()
        {
            var target = new ItemsControl();
            var items  = new AvaloniaList <string> {
                "Foo", "Bar"
            };
            var called = false;

            target.Template = GetTemplate();
            target.Items    = items;
            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();

            ((ILogical)target).LogicalChildren.CollectionChanged                   += (s, e) =>
                                                                             called = e.Action == NotifyCollectionChangedAction.Remove;

            items.Remove("Bar");

            Assert.True(called);
        }
Esempio n. 18
0
        public AmiiboWindowViewModel(StyleableWindow owner, string lastScannedAmiiboId, string titleId)
        {
            _owner      = owner;
            _httpClient = new HttpClient {
                Timeout = TimeSpan.FromMilliseconds(5000)
            };
            LastScannedAmiiboId = lastScannedAmiiboId;
            TitleId             = titleId;

            Directory.CreateDirectory(Path.Join(AppDataManager.BaseDirPath, "system", "amiibo"));

            _amiiboJsonPath = Path.Join(AppDataManager.BaseDirPath, "system", "amiibo", "Amiibo.json");
            _amiiboList     = new List <Amiibo.AmiiboApi>();
            _amiiboSeries   = new ObservableCollection <string>();
            _amiibos        = new AvaloniaList <Amiibo.AmiiboApi>();

            _amiiboLogoBytes = EmbeddedResources.Read("Ryujinx.Ui.Common/Resources/Logo_Amiibo.png");

            _ = LoadContentAsync();
        }
Esempio n. 19
0
        public void MoveRange_Raises_Correct_CollectionChanged_Event()
        {
            var target = new AvaloniaList <int>(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
            var raised = false;

            target.CollectionChanged += (s, e) =>
            {
                Assert.Equal(NotifyCollectionChangedAction.Move, e.Action);
                Assert.Equal(0, e.OldStartingIndex);
                Assert.Equal(10, e.NewStartingIndex);
                Assert.Equal(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, e.OldItems);
                Assert.Equal(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, e.NewItems);
                raised = true;
            };

            target.MoveRange(0, 9, 10);

            Assert.True(raised);
            Assert.Equal(new[] { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, target);
        }
Esempio n. 20
0
    private void Initialize()
    {
        var list = new AvaloniaList <object>();

        var menuItemRefresh = new TabMenuItem("_Refresh");

        menuItemRefresh.Click += MenuItemRefresh_Click;
        list.Add(menuItemRefresh);

        var menuItemReload = new TabMenuItem("_Reload");

        menuItemReload.Click += MenuItemReload_Click;
        list.Add(menuItemReload);

        var menuItemReset = new TabMenuItem("Re_set");

        menuItemReset.Click += MenuItemReset_Click;
        list.Add(menuItemReset);

#if DEBUG
        var menuItemDebug = new TabMenuItem("_Debug");
        menuItemDebug.Click += MenuItemDebug_Click;
        list.Add(menuItemDebug);

        list.Add(new Separator());

        _checkboxAutoLoad = new CheckBox()
        {
            IsChecked = TabInstance.Project.UserSettings.AutoLoad,
        };
        var menuItemAutoLoad = new TabMenuItem()
        {
            Header = "_AutoLoad",
            Icon   = _checkboxAutoLoad,
        };
        menuItemAutoLoad.Click += MenuItemAutoLoad_Click;
        list.Add(menuItemAutoLoad);
#endif

        Items = list;
    }
        protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
        {
            base.OnTemplateApplied(e);
            this.clickButton = this.EnforceInstance <Button>(e, "PART_Button");
            this.menu        = this.EnforceInstance <ContextMenu>(e, "PART_Menu");

            this.InitializeVisualElementsContainer();
            if (this.menu != null && this.Items != null /*&& this.ItemsSource == null*/)
            {
                var list = new AvaloniaList <object>();
                foreach (var newItem in this.Items)
                {
                    this.TryRemoveVisualFromOldTree(newItem);
                    list.Add(newItem);
                }
                menu.Items = list;
            }
            this.RaisePropertyChanged(MenuStyleProperty, null, (IStyle)MenuStyle);
            //RaisePropertyChanged<IStyle>(MenuStyleProperty, null, MenuStyle);
            //this.OnPropertyChanged<IStyle>(MenuStyleProperty, null, new Data.BindingValue<IStyle>( MenuStyle), Data.BindingPriority.Style);
        }
        public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
        {
            var result = new AvaloniaList <T>();
            var values = ((string)value).Split(',');

            foreach (var s in values)
            {
                object v;

                if (TypeUtilities.TryConvert(typeof(T), s, culture, out v))
                {
                    result.Add((T)v);
                }
                else
                {
                    throw new InvalidCastException($"Could not convert '{s}' to {typeof(T)}.");
                }
            }

            return(result);
        }
Esempio n. 23
0
        public void Setting_SelectedIndex_During_Initialize_Should_Select_Item_When_AlwaysSelected_Is_Used()
        {
            var listBox = new ListBox
            {
                SelectionMode = SelectionMode.Single | SelectionMode.AlwaysSelected
            };

            listBox.BeginInit();

            listBox.SelectedIndex = 1;
            var items = new AvaloniaList <string>();

            listBox.Items = items;
            items.Add("A");
            items.Add("B");
            items.Add("C");

            listBox.EndInit();

            Assert.Equal("B", listBox.SelectedItem);
        }
Esempio n. 24
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(AvaloniaProperty.UnsetValue);
            }

            var list = value as IEnumerable <IWizardPageVM>;

            var result = new AvaloniaList <WizardPage>();

            foreach (IWizardPageVM wizardPageVM in list)
            {
                IWizardPageVM vm         = wizardPageVM as IWizardPageVM;
                WizardPage    wizardPage = new WizardPage();
                wizardPage.DataContext = vm;
                result.Add(wizardPage);
            }

            return(result);
        }
Esempio n. 25
0
        public void Only_Subscribes_To_Source_CollectionChanged_When_CollectionChanged_Subscribed()
        {
            var source = new AvaloniaList <string>();
            var target = new ItemsSourceView <string>(source);
            var debug  = (INotifyCollectionChangedDebug)source;

            Assert.Null(debug.GetCollectionChangedSubscribers());

            void Handler(object sender, NotifyCollectionChangedEventArgs e)
            {
            }

            target.CollectionChanged += Handler;

            Assert.NotNull(debug.GetCollectionChangedSubscribers());
            Assert.Equal(1, debug.GetCollectionChangedSubscribers().Length);

            target.CollectionChanged -= Handler;

            Assert.Null(debug.GetCollectionChangedSubscribers());
        }
Esempio n. 26
0
        public void Adding_Selected_Item_Should_Update_Selection()
        {
            var items = new AvaloniaList <Item>(new[]
            {
                new Item(),
                new Item(),
            });

            var target = new SelectingItemsControl
            {
                Items    = items,
                Template = Template(),
            };

            Prepare(target);
            items.Add(new Item {
                IsSelected = true
            });

            Assert.Equal(2, target.SelectedIndex);
            Assert.Equal(items[2], target.SelectedItem);
        }
        public void Removing_Selected_Item_Should_Clear_Selection_With_BeginInit()
        {
            var items = new AvaloniaList <Item>
            {
                new Item(),
                new Item(),
            };

            var target = new SelectingItemsControl();

            target.BeginInit();
            target.Items    = items;
            target.Template = Template();
            target.EndInit();

            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();
            target.SelectedIndex = 0;

            Assert.Equal(items[0], target.SelectedItem);
            Assert.Equal(0, target.SelectedIndex);

            SelectionChangedEventArgs receivedArgs = null;

            target.SelectionChanged += (_, args) => receivedArgs = args;

            var removed = items[0];

            items.RemoveAt(0);

            Assert.Null(target.SelectedItem);
            Assert.Equal(-1, target.SelectedIndex);
            Assert.NotNull(receivedArgs);
            Assert.Empty(receivedArgs.AddedItems);
            Assert.Equal(new[] { removed }, receivedArgs.RemovedItems);
            Assert.False(items.Single().IsSelected);
        }
Esempio n. 28
0
    public static void AddContextMenu(TextBox textBox)
    {
        var contextMenu = new ContextMenu()
        {
            Foreground = Theme.Foreground,
        };

        var keymap = AvaloniaLocator.Current.GetService <PlatformHotkeyConfiguration>();

        var list = new AvaloniaList <object>();

        if (!textBox.IsReadOnly)
        {
            var menuItemCut = new TabMenuItem("Cut");
            menuItemCut.Click += delegate { SendTextBoxKey(textBox, keymap.Cut); };
            list.Add(menuItemCut);
        }

        var menuItemCopy = new TabMenuItem("_Copy");

        menuItemCopy.Click += delegate { SendTextBoxKey(textBox, keymap.Copy); };
        list.Add(menuItemCopy);

        if (!textBox.IsReadOnly)
        {
            var menuItemPaste = new TabMenuItem("Paste");
            menuItemPaste.Click += delegate { SendTextBoxKey(textBox, keymap.Paste); };
            list.Add(menuItemPaste);
        }

        //list.Add(new Separator());

        contextMenu.Items = list;

        textBox.ContextMenu = contextMenu;
    }
Esempio n. 29
0
    // TextBlock control doesn't allow selecting text, so add a Copy command to the context menu
    public static void AddContextMenu(TextBlock textBlock)
    {
        var contextMenu = new ContextMenu();

        var keymap = AvaloniaLocator.Current.GetService <PlatformHotkeyConfiguration>();

        var list = new AvaloniaList <object>();

        var menuItemCopy = new TabMenuItem()
        {
            Header     = "_Copy",
            Foreground = Brushes.Black,
        };

        menuItemCopy.Click += delegate
        {
            ClipBoardUtils.SetText(textBlock.Text);
        };
        list.Add(menuItemCopy);

        contextMenu.Items = list;

        textBlock.ContextMenu = contextMenu;
    }
Esempio n. 30
0
        public void Containers_Correct_After_Clear_Add_Remove()
        {
            // Issue #1936
            var items  = new AvaloniaList <string>(Enumerable.Range(0, 11).Select(x => $"Item {x}"));
            var target = new ListBox
            {
                Template     = ListBoxTemplate(),
                Items        = items,
                ItemTemplate = new FuncDataTemplate <string>((x, _) => new TextBlock {
                    Width = 20, Height = 10
                }),
                SelectedIndex = 0,
            };

            Prepare(target);

            items.Clear();
            items.AddRange(Enumerable.Range(0, 11).Select(x => $"Item {x}"));
            items.Remove("Item 2");

            Assert.Equal(
                items,
                target.Presenter.Panel.Children.Cast <ListBoxItem>().Select(x => (string)x.Content));
        }
Esempio n. 31
0
        public ColorListControlVM(string filepath) : base()
        {
            ColorList = new ObservableCollection <ColorListEntry>();

            Reload(filepath);

            BtnAddColor         = new RelayCommand(o => { AddNewColor(); });
            BtnSaveColors       = new RelayCommand(o => { Save(); });
            BtnRemove           = new RelayCommand(o => { RemoveSelected(); });
            BtnMoveDown         = new RelayCommand(o => { Move(false); });
            BtnMoveUp           = new RelayCommand(o => { Move(true); });
            BtnExportXLSX       = new RelayCommand(o => { ExportXLSX(); });
            base.UnsavedChanges = false;

            ColumnConfig = new AvaloniaList <Column>
            {
                new Column()
                {
                    DataField = "Color", Header = "", Class = "Color", CanResize = false
                },
                new Column()
                {
                    DataField = "Name", Header = _("Name"), Class = "Name", CanResize = true, Width = new GridLength(100)
                },
                new Column()
                {
                    DataField = "Color", Header = _("RGB"), Class = "RGB", CanResize = true, Width = new GridLength(70)
                },
                new Column()
                {
                    DataField = "Count", Header = GetParticularString("Total domino color count", "Count"), Class = "Count", CanResize = true, Width = new GridLength(70)
                }
            };

            ShowProjects = false;
        }
Esempio n. 32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Visual"/> class.
 /// </summary>
 public Visual()
 {
     var visualChildren = new AvaloniaList<IVisual>();
     visualChildren.ResetBehavior = ResetBehavior.Remove;
     visualChildren.Validate = ValidateVisualChild;
     visualChildren.CollectionChanged += VisualChildrenChanged;
     VisualChildren = visualChildren;
 }
Esempio n. 33
0
 public DownloadManager()
 {
     _downloads = new AvaloniaList <Download>();
     Downloads.GetWeakCollectionChangedObservable().Subscribe(x => Log.Information("Downloads changed"));
 }
Esempio n. 34
0
        public void InsertRange_With_Null_Should_Throw_Exception()
        {
            var target = new AvaloniaList<int>();

            Assert.Throws<ArgumentNullException>(() => target.InsertRange(1, null));
        }
Esempio n. 35
0
        public void InsertRange_With_Null_Should_Throw_Exception()
        {
            var target = new AvaloniaList <int>();

            Assert.Throws <ArgumentNullException>(() => target.InsertRange(1, null));
        }
Esempio n. 36
0
        public void RemoveAll_With_Null_Should_Throw_Exception()
        {
            var target = new AvaloniaList <int>();

            Assert.Throws <ArgumentNullException>(() => target.RemoveAll(null));
        }
        public void Adding_Selected_Item_Should_Update_Selection()
        {
            var items = new AvaloniaList<Item>(new[]
            {
                new Item(),
                new Item(),
            });

            var target = new SelectingItemsControl
            {
                Items = items,
                Template = Template(),
            };

            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();
            items.Add(new Item { IsSelected = true });

            Assert.Equal(2, target.SelectedIndex);
            Assert.Equal(items[2], target.SelectedItem);
        }
Esempio n. 38
0
        public void Should_Handle_Duplicate_Items()
        {
            var items = new AvaloniaList<int>(new[] { 1, 2, 1 });

            var target = new ItemsPresenter
            {
                Items = items,
            };

            target.ApplyTemplate();
            items.RemoveAt(2);

            var numbers = target.Panel.Children
                .OfType<ContentPresenter>()
                .Select(x => x.Content)
                .Cast<int>();
            Assert.Equal(new[] { 1, 2 }, numbers);
        }
Esempio n. 39
0
        public void Adding_Item_Should_Raise_CollectionChanged()
        {
            var target = new AvaloniaList<int>(new[] { 1, 2 });
            var raised = false;

            target.CollectionChanged += (s, e) =>
            {
                Assert.Equal(target, s);
                Assert.Equal(NotifyCollectionChangedAction.Add, e.Action);
                Assert.Equal(new[] { 3 }, e.NewItems.Cast<int>());
                Assert.Equal(2, e.NewStartingIndex);

                raised = true;
            };

            target.Add(3);

            Assert.True(raised);
        }
Esempio n. 40
0
        public void Clearing_Items_Should_Raise_CollectionChanged_Remove()
        {
            var target = new AvaloniaList<int>(new[] { 1, 2, 3 });
            var raised = false;

            target.ResetBehavior = ResetBehavior.Remove;
            target.CollectionChanged += (s, e) =>
            {
                Assert.Equal(target, s);
                Assert.Equal(NotifyCollectionChangedAction.Remove, e.Action);
                Assert.Equal(new[] { 1, 2, 3 }, e.OldItems.Cast<int>());
                Assert.Equal(0, e.OldStartingIndex);

                raised = true;
            };

            target.Clear();

            Assert.True(raised);
        }
Esempio n. 41
0
 public Node()
 {
     Children = new AvaloniaList<Node>();
 }
Esempio n. 42
0
        public void Clearing_Items_Should_Raise_CollectionChanged_Reset()
        {
            var target = new AvaloniaList<int>(new[] { 1, 2, 3 });
            var raised = false;

            target.CollectionChanged += (s, e) =>
            {
                Assert.Equal(target, s);
                Assert.Equal(NotifyCollectionChangedAction.Reset, e.Action);

                raised = true;
            };

            target.Clear();

            Assert.True(raised);
        }
Esempio n. 43
0
        public void Removing_Items_Should_Fire_LogicalChildren_CollectionChanged()
        {
            var target = new ItemsControl();
            var items = new AvaloniaList<string> { "Foo", "Bar" };
            var called = false;

            target.Template = GetTemplate();
            target.Items = items;
            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();

            ((ILogical)target).LogicalChildren.CollectionChanged += (s, e) =>
                called = e.Action == NotifyCollectionChangedAction.Remove;

            items.Remove("Bar");

            Assert.True(called);
        }
Esempio n. 44
0
        public void Should_Handle_Null_Items()
        {
            var items = new AvaloniaList<string>(new[] { "foo", null, "bar" });

            var target = new ItemsPresenter
            {
                Items = items,
            };

            target.ApplyTemplate();

            var text = target.Panel.Children.Cast<ContentPresenter>().Select(x => x.Content).ToList();

            Assert.Equal(new[] { "foo", null, "bar" }, text);
            Assert.NotNull(target.ItemContainerGenerator.ContainerFromIndex(0));
            Assert.NotNull(target.ItemContainerGenerator.ContainerFromIndex(1));
            Assert.NotNull(target.ItemContainerGenerator.ContainerFromIndex(2));

            items.RemoveAt(1);

            text = target.Panel.Children.Cast<ContentPresenter>().Select(x => x.Content).ToList();

            Assert.Equal(new[] { "foo", "bar" }, text);
            Assert.NotNull(target.ItemContainerGenerator.ContainerFromIndex(0));
            Assert.NotNull(target.ItemContainerGenerator.ContainerFromIndex(1));
        }
Esempio n. 45
0
        public void RemoveAll_With_Null_Should_Throw_Exception()
        {
            var target = new AvaloniaList<int>();

            Assert.Throws<ArgumentNullException>(() => target.RemoveAll(null));
        }
Esempio n. 46
0
        public void Inserting_Then_Removing_Should_Add_Remove_Containers()
        {
            var items = new AvaloniaList<string>(Enumerable.Range(0, 5).Select(x => $"Item {x}"));
            var toAdd = Enumerable.Range(0, 3).Select(x => $"Added Item {x}").ToArray();
            var target = new ItemsPresenter
            {
                VirtualizationMode = ItemVirtualizationMode.None,
                Items = items,
                ItemTemplate = new FuncDataTemplate<string>(x => new TextBlock { Height = 10 }),
            };

            target.ApplyTemplate();

            Assert.Equal(items.Count, target.Panel.Children.Count);

            foreach (var item in toAdd)
            {
                items.Insert(1, item);
            }

            Assert.Equal(items.Count, target.Panel.Children.Count);

            foreach (var item in toAdd)
            {
                items.Remove(item);
            }

            Assert.Equal(items.Count, target.Panel.Children.Count);
        }
        public void Should_Add_Containers_For_Items_After_Clear()
        {
            var target = CreateTarget(itemCount: 10);
            var defaultItems = (IList<string>)target.Items;
            var items = new AvaloniaList<string>(defaultItems);
            target.Items = items;

            target.ApplyTemplate();
            target.Measure(new Size(100, 100));
            target.Arrange(new Rect(target.DesiredSize));

            Assert.Equal(10, target.Panel.Children.Count);

            items.Clear();

            target.Panel.Measure(new Size(100, 100));
            target.Panel.Arrange(new Rect(target.Panel.DesiredSize));

            target.Measure(new Size(100, 100));
            target.Arrange(new Rect(target.DesiredSize));

            Assert.Equal(0, target.Panel.Children.Count);

            items.AddRange(defaultItems.Select(s => s + " new"));

            target.Panel.Measure(new Size(100, 100));
            target.Panel.Arrange(new Rect(target.Panel.DesiredSize));

            target.Measure(new Size(100, 100));
            target.Arrange(new Rect(target.DesiredSize));

            Assert.Equal(10, target.Panel.Children.Count);
        }
 public SmsViewerModels(SmsViewer view)
 {
     m_Messages = new AvaloniaList <SmsDataItemModel>();
     parent     = view;
 }
        public void Removing_Selected_Item_Should_Clear_Selection()
        {
            var items = new AvaloniaList<Item>
            {
                new Item(),
                new Item(),
            };

            var target = new SelectingItemsControl
            {
                Items = items,
                Template = Template(),
            };

            target.ApplyTemplate();
            target.SelectedIndex = 1;

            Assert.Equal(items[1], target.SelectedItem);
            Assert.Equal(1, target.SelectedIndex);

            items.RemoveAt(1);

            Assert.Equal(null, target.SelectedItem);
            Assert.Equal(-1, target.SelectedIndex);
        }
Esempio n. 50
0
 public static void SetRowSpan(Control?element, AvaloniaList <int> value)
 {
     Contract.Requires <ArgumentNullException>(element != null);
     element !.SetValue(RowSpanProperty, value);
 }
Esempio n. 51
0
        public void LayoutManager_Should_Measure_Arrange_All()
        {
            var virtualizationMode = ItemVirtualizationMode.Simple;

            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var items = new AvaloniaList <string>(Enumerable.Range(1, 7).Select(v => v.ToString()));

                var wnd = new Window()
                {
                    SizeToContent = SizeToContent.WidthAndHeight
                };

                wnd.IsVisible = true;

                var target = new ListBox();

                wnd.Content = target;

                var lm = wnd.LayoutManager;

                target.Height             = 110;
                target.Width              = 50;
                target.DataContext        = items;
                target.VirtualizationMode = virtualizationMode;

                target.ItemTemplate = new FuncDataTemplate <object>((c, _) =>
                {
                    var tb = new TextBlock()
                    {
                        Height = 10, Width = 30
                    };
                    tb.Bind(TextBlock.TextProperty, new Data.Binding());
                    return(tb);
                }, true);

                lm.ExecuteInitialLayoutPass();

                target.Items = items;

                lm.ExecuteLayoutPass();

                items.Insert(3, "3+");
                lm.ExecuteLayoutPass();

                items.Insert(4, "4+");
                lm.ExecuteLayoutPass();

                //RESET
                items.Clear();
                foreach (var i in Enumerable.Range(1, 7))
                {
                    items.Add(i.ToString());
                }

                //working bit better with this line no outof memory or remaining to arrange/measure ???
                //lm.ExecuteLayoutPass();

                items.Insert(2, "2+");

                lm.ExecuteLayoutPass();
                //after few more layout cycles layoutmanager shouldn't hold any more visual for measure/arrange
                lm.ExecuteLayoutPass();
                lm.ExecuteLayoutPass();

                var flags     = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic;
                var toMeasure = lm.GetType().GetField("_toMeasure", flags).GetValue(lm) as System.Collections.Generic.IEnumerable <Layout.ILayoutable>;
                var toArrange = lm.GetType().GetField("_toArrange", flags).GetValue(lm) as System.Collections.Generic.IEnumerable <Layout.ILayoutable>;

                Assert.Equal(0, toMeasure.Count());
                Assert.Equal(0, toArrange.Count());
            }
        }
Esempio n. 52
0
 public MenuFlyout()
 {
     _items = new AvaloniaList <object>();
 }
Esempio n. 53
0
 public ItemsControlView()
 {
     DataTemplates = new AvaloniaList <IDataTemplate>();
 }
        public void HotKeyManager_Should_Release_Reference_When_Control_In_Item_Template_Detached()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var styler = new Mock <Styler>();

                AvaloniaLocator.CurrentMutable
                .Bind <IWindowingPlatform>().ToConstant(new WindowingPlatformMock())
                .Bind <IStyler>().ToConstant(styler.Object);

                var gesture1 = new KeyGesture(Key.A, KeyModifiers.Control);

                var weakReferences = new List <WeakReference>();
                var tl             = new Window {
                    SizeToContent = SizeToContent.WidthAndHeight, IsVisible = true
                };
                var lm = tl.LayoutManager;

                var keyGestures = new AvaloniaList <KeyGesture> {
                    gesture1
                };
                var listBox = new ListBox
                {
                    Width              = 100,
                    Height             = 100,
                    VirtualizationMode = ItemVirtualizationMode.None,
                    // Create a button with binding to the KeyGesture in the template and add it to references list
                    ItemTemplate = new FuncDataTemplate(typeof(KeyGesture), (o, scope) =>
                    {
                        var keyGesture = o as KeyGesture;
                        var button     = new Button
                        {
                            DataContext = keyGesture, [!Button.HotKeyProperty] = new Binding("")
                        };
                        weakReferences.Add(new WeakReference(button, true));
                        return(button);
                    })
                };
                // Add the listbox and render it
                tl.Content = listBox;
                lm.ExecuteInitialLayoutPass();
                listBox.Items = keyGestures;
                lm.ExecuteLayoutPass();

                // Let the button detach when clearing the source items
                keyGestures.Clear();
                lm.ExecuteLayoutPass();

                // Add it again to double check,and render
                keyGestures.Add(gesture1);
                lm.ExecuteLayoutPass();

                keyGestures.Clear();
                lm.ExecuteLayoutPass();

                // The button should be collected since it's detached from the listbox
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();

                Assert.True(weakReferences.Count > 0);
                foreach (var weakReference in weakReferences)
                {
                    Assert.Null(weakReference.Target);
                }
            }
        }
Esempio n. 55
0
        public void InsertRange_Past_End_Should_Throw_Exception()
        {
            var target = new AvaloniaList<int>();

            Assert.Throws<ArgumentOutOfRangeException>(() => target.InsertRange(1, new List<int>() { 1 }));
        }