示例#1
0
        public void Clicking_On_Control_Toggles_ContextMenu()
        {
            using (Application())
            {
                popupImpl.Setup(x => x.Show()).Verifiable();
                popupImpl.Setup(x => x.Hide()).Verifiable();

                var sut    = new ContextMenu();
                var target = new Panel
                {
                    ContextMenu = sut
                };

                var window = new Window {
                    Content = target
                };
                window.ApplyTemplate();
                window.Presenter.ApplyTemplate();

                _mouse.Click(target, MouseButton.Right);

                Assert.True(sut.IsOpen);

                _mouse.Click(target);

                Assert.False(sut.IsOpen);
                popupImpl.Verify(x => x.Show(), Times.Once);
                popupImpl.Verify(x => x.Hide(), Times.Once);
            }
        }
示例#2
0
        public void Context_Menu_Can_Be_Set_In_Style()
        {
            using (Application())
            {
                var xaml = @"
<Window xmlns='https://github.com/avaloniaui'
        xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
    <Window.Styles>
        <Style Selector='TextBlock'>
            <Setter Property='ContextMenu'>
                <ContextMenu>
                    <MenuItem>Foo</MenuItem>
                </ContextMenu>
            </Setter>
        </Style>
	</Window.Styles>

    <StackPanel>
        <TextBlock Name='target1'/>
        <TextBlock Name='target2'/>
    </StackPanel>
</Window>";

                var loader  = new AvaloniaXamlLoader();
                var window  = (Window)loader.Load(xaml);
                var target1 = window.Find <TextBlock>("target1");
                var target2 = window.Find <TextBlock>("target2");
                var mouse   = new MouseTestHelper();

                Assert.NotNull(target1.ContextMenu);
                Assert.NotNull(target2.ContextMenu);
                Assert.Same(target1.ContextMenu, target2.ContextMenu);

                window.Show();

                var menu = target1.ContextMenu;
                mouse.Click(target1, MouseButton.Right);
                Assert.True(menu.IsOpen);
                mouse.Click(target2, MouseButton.Right);
                Assert.True(menu.IsOpen);
            }
        }
示例#3
0
        public void Clicking_On_Control_Toggles_ContextMenu()
        {
            using (Application())
            {
                popupImpl.Setup(x => x.Show(true, false)).Verifiable();
                popupImpl.Setup(x => x.Hide()).Verifiable();

                var sut    = new ContextMenu();
                var target = new Panel
                {
                    ContextMenu = sut
                };

                var window = PreparedWindow(target);
                window.Show();
                var overlay = LightDismissOverlayLayer.GetLightDismissOverlayLayer(window);

                _mouse.Click(target, MouseButton.Right);

                Assert.True(sut.IsOpen);

                _mouse.Down(overlay);
                _mouse.Up(target);

                Assert.False(sut.IsOpen);
                popupImpl.Verify(x => x.Show(true, false), Times.Once);
                popupImpl.Verify(x => x.Hide(), Times.Once);
            }
        }
示例#4
0
        public void Context_Menu_In_Resources_Can_Be_Shared()
        {
            using (Application())
            {
                var xaml = @"
<Window xmlns='https://github.com/avaloniaui'
        xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
    <Window.Resources>
        <ContextMenu x:Key='contextMenu'>
            <MenuItem>Foo</MenuItem>
        </ContextMenu>
	</Window.Resources>

    <StackPanel>
        <TextBlock Name='target1' ContextMenu='{StaticResource contextMenu}'/>
        <TextBlock Name='target2' ContextMenu='{StaticResource contextMenu}'/>
    </StackPanel>
</Window>";

                var window  = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
                var target1 = window.Find <TextBlock>("target1");
                var target2 = window.Find <TextBlock>("target2");
                var mouse   = new MouseTestHelper();

                Assert.NotNull(target1.ContextMenu);
                Assert.NotNull(target2.ContextMenu);
                Assert.Same(target1.ContextMenu, target2.ContextMenu);

                window.Show();

                var menu = target1.ContextMenu;
                mouse.Click(target1, MouseButton.Right);
                Assert.True(menu.IsOpen);
                mouse.Click(target2, MouseButton.Right);
                Assert.True(menu.IsOpen);
            }
        }
        public void Clicking_Item_Should_Select_It()
        {
            var target = new ListBox
            {
                Template = new FuncControlTemplate(CreateListBoxTemplate),
                Items    = new[] { "Foo", "Bar", "Baz " },
            };

            ApplyTemplate(target);
            _mouse.Click(target.Presenter.Panel.Children[0]);

            Assert.Equal(0, target.SelectedIndex);
        }
示例#6
0
        public void Clicking_Item_Should_Select_It()
        {
            using (UnitTestApplication.Start())
            {
                var target = new ListBox
                {
                    Template = new FuncControlTemplate(CreateListBoxTemplate),
                    Items    = new[] { "Foo", "Bar", "Baz " },
                };
                AvaloniaLocator.CurrentMutable.Bind <PlatformHotkeyConfiguration>().ToConstant(new Mock <PlatformHotkeyConfiguration>().Object);
                ApplyTemplate(target);
                _mouse.Click(target.Presenter.Panel.Children[0]);

                Assert.Equal(0, target.SelectedIndex);
            }
        }
示例#7
0
 private void RaisePressedEvent(ListBox listBox, ListBoxItem item, MouseButton mouseButton)
 {
     _mouse.Click(listBox, item, mouseButton);
 }