예제 #1
0
        public void TextBox_With_Xaml_Binding_Is_Freed()
        {
            using (Start())
            {
                Func <Window> run = () =>
                {
                    var window = new Window
                    {
                        DataContext = new Node {
                            Name = "foo"
                        },
                        Content = new TextBox()
                    };

                    var binding = new Avalonia.Data.Binding
                    {
                        Path = "Name"
                    };

                    var textBox = (TextBox)window.Content;
                    textBox.Bind(TextBox.TextProperty, binding);

                    window.Show();

                    // Do a layout and make sure that TextBox gets added to visual tree and its
                    // Text property set.
                    window.LayoutManager.ExecuteInitialLayoutPass(window);
                    Assert.IsType <TextBox>(window.Presenter.Child);
                    Assert.Equal("foo", ((TextBox)window.Presenter.Child).Text);

                    // Clear the content and DataContext and ensure the TextBox is removed.
                    window.Content     = null;
                    window.DataContext = null;
                    window.LayoutManager.ExecuteLayoutPass();
                    Assert.Null(window.Presenter.Child);

                    return(window);
                };

                var result = run();

                dotMemory.Check(memory =>
                                Assert.Equal(0, memory.GetObjects(where => where.Type.Is <TextBox>()).ObjectsCount));
                dotMemory.Check(memory =>
                                Assert.Equal(0, memory.GetObjects(where => where.Type.Is <Node>()).ObjectsCount));
            }
        }
        void UpdateToolbar()
        {
            //Control.PrimaryTopBarCommands.Clear();
            //Control.SecondaryTopBarCommands.Clear();

            foreach (var item in Element.ToolbarItems)
            {
                var appBar = new FormsAppBarButton()
                {
                    DataContext = item
                };

                var iconBinding = new Avalonia.Data.Binding(nameof(item.Icon))
                {
                    Converter = new IconConveter()
                };

                //appBar.SetBinding(FormsAppBarButton.IconProperty, iconBinding);
                //appBar.SetBinding(FormsAppBarButton.LabelProperty, nameof(item.Text));
                //appBar.SetValue(ControlAttached.PriorityProperty, item.Priority);

                appBar.Click += (sender, e) =>
                {
                    if (appBar.DataContext is ToolbarItem toolbarItem)
                    {
                        // TODO:
                        //toolbarItem.Activate();
                    }
                };

                //if (item.Order == ToolbarItemOrder.Default || item.Order == ToolbarItemOrder.Primary)
                //	Control.PrimaryTopBarCommands.Add(appBar);
                //else
                //	Control.SecondaryTopBarCommands.Add(appBar);
            }
        }