当前位置: 首页>>代码示例>>C#>>正文


C# Button.Focus方法代码示例

本文整理汇总了C#中Button.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# Button.Focus方法的具体用法?C# Button.Focus怎么用?C# Button.Focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Button的用法示例。


在下文中一共展示了Button.Focus方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShouldClosePopupOnFocusLost

        public virtual void ShouldClosePopupOnFocusLost()
        {
            Picker picker = DefaultPickerToTest;
            Button button = new Button { Content = "A button to set focus to", VerticalAlignment = VerticalAlignment.Top };
            TestPanel.Children.Add(button);

            bool opened = false;
            bool closed = false;
            picker.DropDownOpened += (sender, e) => opened = true;
            picker.DropDownClosed += (sender, e) => closed = true;

            TestPanel.Children.Add(picker);

            EnqueueCallback(() => picker.IsDropDownOpen = true);
            EnqueueCallback(() => Assert.IsTrue(opened));
            EnqueueCallback(() => button.Focus());
            EnqueueConditional(() => closed);
            EnqueueTestComplete();
        }
开发者ID:modulexcite,项目名称:SilverlightToolkit,代码行数:19,代码来源:PickerTest.cs

示例2: SelectionInactiveOnLostFocus

        public virtual void SelectionInactiveOnLostFocus()
        {
            StackPanel root = new StackPanel();
            TreeView view = new TreeView();
            TreeViewItem item = new TreeViewItem { Header = "Item" };
            view.Items.Add(item);
            Button other = new Button { Content = "Button" };
            root.Children.Add(view);
            root.Children.Add(other);

            TestAsync(
                root,
                () => Assert.IsFalse(item.IsSelected, "Item should not be selected initially!"),
                () => Assert.IsFalse(item.IsSelectionActive, "Item should not have inactive selection initially!"),
                () => item.Focus(),
                () => Assert.IsTrue(item.IsSelected, "Item should be selected after focus!"),
                () => Assert.IsTrue(item.IsSelectionActive, "Item should not have inactive selection after focus!"),
                () => other.Focus(),
                () => Assert.IsTrue(item.IsSelected, "Item should be selected after focusing another element!"),
                () => Assert.IsFalse(item.IsSelectionActive, "Item should have an inactive selection after focusing another element!"));
        }
开发者ID:kvervo,项目名称:HorizontalLoopingSelector,代码行数:21,代码来源:TreeViewItemTest.cs

示例3: LostFocusWithDropDown

        public void LostFocusWithDropDown()
        {
            // TODO: Evaluate improvements to remove the Sleep.

            Button button = new Button { Content = "This is a Button" };
            OverriddenAutoCompleteBox control = GetDerivedAutoComplete();

            TestPanel.Children.Add(button);

            bool isLoaded = false;
            control.Loaded += delegate { isLoaded = true; };
            EnqueueCallback(() => TestPanel.Children.Add(control));
            EnqueueConditional(() => isLoaded);

            EnqueueCallback(() => Assert.IsNotNull(control.TextBox, "The TextBox part could not be retrieved."));
            EnqueueCallback(() => control.Focus());
            EnqueueCallback(() => control.TextBox.Text = "accounti");
            EnqueueConditional(() => control.SearchText == "accounti");
            EnqueueCallback(() => StringAssert.Equals(control.TextBox.Text, "accounting"));
            EnqueueCallback(() => Assert.IsTrue(control.IsDropDownOpen));
            EnqueueCallback(() => button.Focus());
            
            // This will prevent a timeout
            EnqueueDelay(TimeSpan.FromSeconds(0.1));
            EnqueueCallback(() => Assert.IsFalse(control.IsDropDownOpen, "The drop down did not close. Please check that the focus did change."));
            EnqueueTestComplete();
        }
开发者ID:kvervo,项目名称:HorizontalLoopingSelector,代码行数:27,代码来源:AutoCompleteBoxTest.cs

示例4: ExpanderButtonFocusActivatesSelection

        public virtual void ExpanderButtonFocusActivatesSelection()
        {
            StackPanel root = new StackPanel();
            TreeView view = new TreeView();
            TreeViewItem item = new TreeViewItem { Header = "Item" };
            Button button = new Button { Content = "Button" };
            view.Items.Add(item);
            root.Children.Add(view);
            root.Children.Add(button);
            ToggleButton ExpanderButton = null;

            TestAsync(
                5,
                root,
                () => item.Focus(),
                () => Assert.IsTrue(item.IsSelected, "Item should be selected!"),
                () => Assert.IsTrue(item.IsSelectionActive, "Selection should be active after focusing!"),
                () => button.Focus(),
                () => Assert.IsFalse(item.IsSelectionActive, "Selection should be inactive after focusing on something else!"),
                () => ExpanderButton = item.GetVisualChild("ExpanderButton") as ToggleButton,
                () => Assert.IsNotNull(ExpanderButton, "Failed to find template part ExpanderButton!"),
                () => ExpanderButton.Focus(),
                () => Assert.IsTrue(item.IsSelectionActive, "Selection should be active after focusing ExpanderButton!"));
        }
开发者ID:kvervo,项目名称:HorizontalLoopingSelector,代码行数:24,代码来源:TreeViewItemTest.cs

示例5: LostFocus

        public void LostFocus()
        {
            // TODO: Evaluate improvements to remove the Sleep.

            Button button = new Button { Content = "This is a Button" };
            OverriddenAutoCompleteBox control = GetDerivedAutoComplete();

            TestPanel.Children.Add(button);

            bool lostFocus = false;
            bool isLoaded = false;
            control.Loaded += delegate { isLoaded = true; };
            control.LostFocus += (s, e) => lostFocus = true;
            EnqueueCallback(() => TestPanel.Children.Add(control));
            EnqueueConditional(() => isLoaded);

            EnqueueCallback(() => Assert.IsNotNull(control.TextBox, "The TextBox part could not be retrieved."));
            EnqueueCallback(() => control.Focus());
            EnqueueDelay(TimeSpan.FromSeconds(0.1));
            EnqueueCallback(() => Assert.IsFalse(control.IsDropDownOpen));
            EnqueueDelay(TimeSpan.FromSeconds(0.1));
            EnqueueCallback(() => button.Focus());
            EnqueueDelay(TimeSpan.FromSeconds(0.1));
            EnqueueCallback(() => Assert.IsFalse(control.IsDropDownOpen));
            EnqueueCallback(() => Assert.IsTrue(lostFocus, "Focus was not lost. The Silverlight host may not have had focus itself."));

            EnqueueTestComplete();
        }
开发者ID:kvervo,项目名称:HorizontalLoopingSelector,代码行数:28,代码来源:AutoCompleteBoxTest.cs


注:本文中的Button.Focus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。