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


C# Button.Focus方法代码示例

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


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

示例1: OnApplyTemplate

        public override void OnApplyTemplate()
        {
            FloatingWindow parent = this.Parent as FloatingWindow;
            if (parent != null)
            {
                parent.KeyDown -= MessageBoxDialogParent_KeyDown;
            }

            if (btnOK != null)
                btnOK.Click -= button_Click;

            if (btnCancel != null)
                btnCancel.Click -= button_Click;

            base.OnApplyTemplate();

            btnOK = GetTemplateChild(OK_BUTTON_NAME) as Button;
            if (btnOK != null)
            {
                btnOK.Click += button_Click;
                btnOK.Focus();
            }
            btnCancel = GetTemplateChild(CANCEL_BUTTON_NAME) as Button;
            if (btnCancel != null)
                btnCancel.Click += button_Click;

            parent = this.Parent as FloatingWindow;
            if (parent != null)
            {
                parent.KeyDown -= MessageBoxDialogParent_KeyDown;
                parent.KeyDown += MessageBoxDialogParent_KeyDown;
            }
        }
开发者ID:konglingjie,项目名称:arcgis-viewer-silverlight,代码行数:33,代码来源:MessageBoxDialog.cs

示例2: LoadControl

        private void LoadControl(Button actionButton)
        {
            if (_currentButton != null)
                _currentButton.FontWeight = FontWeights.Normal;
            _currentButton = actionButton;
            _currentButton.FontWeight = FontWeights.Bold;

            SetDefaultAlignments();

            actionButton.Focus();

            object uc = _navButtonRegistry[actionButton];

            // Convert from a Type to an instance of the type
            if (!(uc is UserControl))
            {
                uc = (UserControl) Activator.CreateInstance((Type) uc);
                _navButtonRegistry[actionButton] = uc;
            }

            contentMain.Content = uc;

            var configUserControl = ((ActionUserControl) uc);
            MyViewModel.ConfigTitle = configUserControl.ConfigTitle;

            DoApplyChanges(false);
        }
开发者ID:sgh1986915,项目名称:.net-braintree-spa,代码行数:27,代码来源:MainWindow.xaml.cs

示例3: Setup

        /// <summary>
        /// Constructor.
        /// </summary>
        public Setup()
        {
            Logger.Info("Entering constructor.");

            // Defines how to show the setup window.
            Controller.ShowWindowEvent += delegate
            {
                Dispatcher.BeginInvoke((Action)delegate
                {
                    Logger.Info("Entering ShowWindowEvent.");
                    Show();
                    Activate();
                    BringIntoView();
                    Logger.Info("Exiting ShowWindowEvent.");
                });
            };

            // Defines how to hide the setup windows.
            Controller.HideWindowEvent += delegate
            {
                Dispatcher.BeginInvoke((Action)delegate
                {
                    Hide();
                });
            };

            // Defines what to do when changing page.
            // The remote folder addition wizard has several steps.
            Controller.ChangePageEvent += delegate(PageType type)
            {
                Dispatcher.BeginInvoke((Action)delegate
                {
                    Logger.Info("Entering ChangePageEvent.");
                    Reset();

                    // Show appropriate setup page.
                    switch (type)
                    {
                        // Welcome page that shows up at first run.
                        #region Page Setup
                        case PageType.Setup:
                            {
                                // UI elements.

                                Header = Properties_Resources.Welcome;
                                Description = Properties_Resources.Intro;

                                Button cancel_button = new Button()
                                {
                                    Content = Properties_Resources.Cancel
                                };

                                Button continue_button = new Button()
                                {
                                    Content = Properties_Resources.Continue,
                                    IsEnabled = false
                                };

                                Buttons.Add(continue_button);
                                Buttons.Add(cancel_button);

                                continue_button.Focus();

                                // Actions.

                                Controller.UpdateSetupContinueButtonEvent += delegate(bool enabled)
                                {
                                    Dispatcher.BeginInvoke((Action)delegate
                                    {
                                        continue_button.IsEnabled = enabled;
                                    });
                                };

                                cancel_button.Click += delegate
                                {
                                    Dispatcher.BeginInvoke((Action)delegate
                                    {
                                        Program.UI.StatusIcon.Dispose();
                                        Controller.SetupPageCancelled();
                                    });
                                };

                                continue_button.Click += delegate
                                {
                                    Controller.SetupPageCompleted();
                                };

                                Controller.CheckSetupPage();

                                break;
                            }
                        #endregion

                        #region Page Tutorial
                        case PageType.Tutorial:
                            {
                                switch (Controller.TutorialCurrentPage)
//.........这里部分代码省略.........
开发者ID:prignony,项目名称:CmisSync,代码行数:101,代码来源:Setup.cs

示例4: FocusTest3

		public void FocusTest3 ()
		{
			// Show that focus is preserved when an element is added/removed from
			// the visual tree
			bool gotfocus = false;
			bool lostfocus = false;
			Button b = new Button ();

			Enqueue (() => {
				TestPanel.Children.Add (b);
				b.Focus ();
			});
			Enqueue (() => {
				Assert.IsFalse (gotfocus, "#1");
				Assert.IsFalse (lostfocus, "#2");

				TestPanel.Children.Clear ();
				Assert.IsNull (FocusManager.GetFocusedElement (), "#3");
			});
			Enqueue (() => {
				Assert.IsFalse (gotfocus, "#4");
				Assert.IsFalse (lostfocus, "#5");

				TestPanel.Children.Add (b);
				Assert.IsNull (FocusManager.GetFocusedElement (), "#6");
			});
			Enqueue (() => {
				Assert.IsFalse (gotfocus, "#7");
				Assert.IsFalse (lostfocus, "#8");
			});
			EnqueueTestComplete ();
		}
开发者ID:dfr0,项目名称:moon,代码行数:32,代码来源:ControlTest.cs

示例5: SparkleSetup

        public SparkleSetup()
        {
            Controller.ShowWindowEvent += delegate {
               Dispatcher.BeginInvoke ((Action) delegate {
                    Show ();
                    Activate ();
                    BringIntoView ();
                });
            };

            Controller.HideWindowEvent += delegate {
                Dispatcher.BeginInvoke ((Action) delegate {
                    Hide ();
                });
            };

            Controller.ChangePageEvent += delegate (PageType type, string [] warnings) {
                Dispatcher.BeginInvoke ((Action) delegate {
                    Reset ();

                    switch (type) {
                    case PageType.Setup: {
                        Header      = "Welcome to CmisSync!";
                        Description = "CmisSync allows you to keep in sync with any CMIS-compatible repository, and use your documents even when offline.\nIt is like Dropbox for Enterprise Content Management!\nAvailable for Linux, Mac, Windows.";

                        Button cancel_button = new Button () {
                            Content = "Cancel"
                        };

                        Button continue_button = new Button () {
                            Content = "Continue",
                            IsEnabled = false
                        };

                        Buttons.Add (continue_button);
                        Buttons.Add (cancel_button);

                        continue_button.Focus();

                        Controller.UpdateSetupContinueButtonEvent += delegate (bool enabled) {
                            Dispatcher.BeginInvoke ((Action) delegate {
                                continue_button.IsEnabled = enabled;
                            });
                        };

                        cancel_button.Click += delegate {
                            Dispatcher.BeginInvoke ((Action) delegate {
                                Program.UI.StatusIcon.Dispose ();
                                Controller.SetupPageCancelled ();
                            });
                        };

                        continue_button.Click += delegate {
                            Controller.SetupPageCompleted ();
                        };

                        Controller.CheckSetupPage ();

                        break;
                    }

                    case PageType.Invite: {
                        Header      = "You've received an invite!";
                           Description = "Do you want to add this project to SparkleShare?";

                        TextBlock address_label = new TextBlock () {
                            Text = "Address:",
                            Width = 150,
                            TextAlignment = TextAlignment.Right
                        };

                        TextBlock address_value = new TextBlock () {
                            Text  = Controller.PendingInvite.Address,
                            Width = 175,
                            FontWeight = FontWeights.Bold
                        };

                        TextBlock path_label = new TextBlock () {
                            Text  = "Remote Path:",
                            Width = 150,
                            TextAlignment = TextAlignment.Right
                        };

                        TextBlock path_value = new TextBlock () {
                            Width = 175,
                            Text = Controller.PendingInvite.RemotePath,
                            FontWeight = FontWeights.Bold
                        };

                        Button cancel_button = new Button () {
                            Content = "Cancel"
                        };

                        Button add_button = new Button () {
                            Content = "Add"
                        };

                        ContentCanvas.Children.Add (address_label);
                        Canvas.SetLeft (address_label, 180);
                        Canvas.SetTop (address_label, 200);
//.........这里部分代码省略.........
开发者ID:smcardle,项目名称:CmisSync,代码行数:101,代码来源:SparkleSetup.cs

示例6: FocusTest

		public void FocusTest ()
		{
			// Show that Controls can be focused before they are loaded
			bool gotfocus = false;
			Button b = new Button ();
			b.GotFocus += delegate { gotfocus = true; };

			Assert.IsFalse (b.Focus (), "#1");
			TestPanel.Children.Add (b);
			Assert.IsTrue (b.Focus (), "#2");
			Enqueue (() => { });
			Enqueue (() => Assert.IsFalse (gotfocus, "#3"));
			EnqueueTestComplete ();
		}
开发者ID:dfr0,项目名称:moon,代码行数:14,代码来源:ControlTest.cs

示例7: FocusTest2

		public void FocusTest2 ()
		{
			// Show that focus is lost when the control is removed from the
			// visual tree
			Button b = new Button ();
			TestPanel.Children.Add (b);
			b.Focus ();
			Assert.AreEqual (b, FocusManager.GetFocusedElement (), "#1");
			TestPanel.Children.Clear ();
			Assert.IsNull (FocusManager.GetFocusedElement (), "#2");
		}
开发者ID:dfr0,项目名称:moon,代码行数:11,代码来源:ControlTest.cs

示例8: 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:royosherove,项目名称:cthru,代码行数:24,代码来源:TreeViewItemTest.cs

示例9: TagTest2

		public void TagTest2 ()
		{
			Button b = new Button ();
			TestPanel.Children.Add (b);
			b.ApplyTemplate ();
			
			Enqueue (() => {
				TestPanel.Tag = b;
				TestPanel.Tag = null;
				Assert.IsTrue (b.Focus (), "#1");
			});
			EnqueueTestComplete ();
		}
开发者ID:dfr0,项目名称:moon,代码行数:13,代码来源:FrameworkElementTest.cs

示例10: 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:royosherove,项目名称:cthru,代码行数:21,代码来源:TreeViewItemTest.cs

示例11: btn_ToLarge

 private void btn_ToLarge(Button btn)
 {
     btn.Focus();
     Launcher launcher = (Launcher)btn.Tag;
     DoubleAnimation anim = AnimButtonSize(btn.Width, launcher.Width * 1.2);
     btn.BeginAnimation(Button.WidthProperty, anim);
     btn.BeginAnimation(Button.HeightProperty, anim);
 }
开发者ID:GeekJosh,项目名称:BertUI,代码行数:8,代码来源:MainWindow.xaml.cs

示例12: FocusPropertyObjectChange

        public void FocusPropertyObjectChange() {
            TextBox control_1 = new TextBox() { IsReadOnly = false };
            TextBox control_2 = new TextBox() { IsReadOnly = false };
            TestControl controlWithProperty = new TestControl();
            FocusBehavior behavior = new FocusBehavior() { PropertyName = "IsReadOnly", SourceObject = control_1 };
            Interaction.GetBehaviors(controlWithProperty).Add(behavior);
            behavior.FocusDelay = TimeSpan.FromMilliseconds(0);
            Grid grid = new Grid();
            Button button = new Button();
            grid.Children.Add(button);
            grid.Children.Add(controlWithProperty);
            grid.Children.Add(control_1);
            grid.Children.Add(control_2);
            Window.Content = grid;
            EnqueueShowWindow();

            EnqueueCallback(() => {
                CheckUnfocusedElement(controlWithProperty);
                control_1.IsReadOnly = true;
                CheckFocusedElement(controlWithProperty);
                button.Focus();
                behavior.SourceObject = control_2;
                CheckUnfocusedElement(controlWithProperty);
                control_2.IsReadOnly = true;
                CheckFocusedElement(controlWithProperty);
            });
            EnqueueTestComplete();
        }
开发者ID:JustGitHubUser,项目名称:DevExpress.Mvvm.Free,代码行数:28,代码来源:FocusBehaviorTests.cs

示例13: AboutDialog

        public AboutDialog(Window owner)
        {
            // Get attributes from assembly.
            // Get this executing assembly to access attributes.
            Assembly asmbly = Assembly.GetExecutingAssembly();

            // Get the AssemblyTitle attribute for the program name.
            AssemblyTitleAttribute title =
                (AssemblyTitleAttribute)asmbly.GetCustomAttributes(
                    typeof(AssemblyTitleAttribute), false)[0];
            string strTitle = title.Title;

            // Get the AssemblyFileVersion attribute.
            AssemblyFileVersionAttribute version =
                (AssemblyFileVersionAttribute)asmbly.GetCustomAttributes(
                    typeof(AssemblyFileVersionAttribute), false)[0];
            string strVersion = version.Version.Substring(0, 3);

            // Get the AssemblyCopyright attribute.
            AssemblyCopyrightAttribute copy =
                (AssemblyCopyrightAttribute)asmbly.GetCustomAttributes(
                    typeof(AssemblyCopyrightAttribute), false)[0];
            string strCopyright = copy.Copyright;

            // Standard window properties for dialog boxes.
            Title = "About " + strTitle;
            ShowInTaskbar = false;
            SizeToContent = SizeToContent.WidthAndHeight;
            ResizeMode = ResizeMode.NoResize;
            Left = owner.Left + 96;
            Top = owner.Top + 96;

            // Create StackPanel as content of window.
            StackPanel stackMain = new StackPanel();
            Content = stackMain;

            // Create TextBlock for program name.
            TextBlock txtblk = new TextBlock();
            txtblk.Text = strTitle + " Version " + strVersion;
            txtblk.FontFamily = new FontFamily("Times New Roman");
            txtblk.FontSize = 32;       // 24 points
            txtblk.FontStyle = FontStyles.Italic;
            txtblk.Margin = new Thickness(24);
            txtblk.HorizontalAlignment = HorizontalAlignment.Center;
            stackMain.Children.Add(txtblk);

            // Create TextBlock for copyright.
            txtblk = new TextBlock();
            txtblk.Text = strCopyright;
            txtblk.FontSize = 20;       // 15 points.
            txtblk.HorizontalAlignment = HorizontalAlignment.Center;
            stackMain.Children.Add(txtblk);

            // Create TextBlock for Web site link.
            Run run = new Run("www.GrapeCity.com");
            Hyperlink link = new Hyperlink(run);
            link.Click += LinkOnClick;
            txtblk = new TextBlock(link);
            txtblk.FontSize = 20;
            txtblk.HorizontalAlignment = HorizontalAlignment.Center;
            stackMain.Children.Add(txtblk);

            // Create OK button.
            Button btn = new Button();
            btn.Content = "OK";
            btn.IsDefault = true;
            btn.IsCancel = true;
            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.MinWidth = 48;
            btn.Margin = new Thickness(24);
            btn.Click += OkOnClick;
            stackMain.Children.Add(btn);

            btn.Focus();
        }
开发者ID:powernick,项目名称:CodeLib,代码行数:75,代码来源:AboutDialog.cs

示例14: AboutDialog

        public AboutDialog(Window owner)
        {
            //어셈블리에서 속성을 구함..  파일 제목 및 버젼 등등 프로그램의 정보를 표시하기 위함임.

            //속성에 접근하기 위해 executing assembly를 구함
            Assembly asmbly = Assembly.GetExecutingAssembly();

            //프로그램 이름을 위해 AssemblyTitle 속성을 구함
            AssemblyTitleAttribute title = (AssemblyTitleAttribute)asmbly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0];
            string strTitle = title.Title;

            //AssemblyFileVersion 속성을 구함(버젼 속성)

            AssemblyFileVersionAttribute version = (AssemblyFileVersionAttribute)asmbly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false)[0];
            string strVersion = version.Version.Substring(0, 3);

            //AssemblyCopyRight 속성을 구함(저작권 관련 속성)
            AssemblyCopyrightAttribute copy = (AssemblyCopyrightAttribute)asmbly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false)[0];
            string strCopyright = copy.Copyright;

            //대화상자의 표준 윈도우 프로퍼티

            Title = "About" + strTitle;                              //Dialog 타이틀바의 내용
            ShowInTaskbar = false;                                  //작업 표시줄에 표현 여부
            SizeToContent = SizeToContent.WidthAndHeight;           //창의 너비와 높이가 콘텐츠의 너비와 높이에 맞게 설정
            ResizeMode = ResizeMode.NoResize;                       //창크기 조정 여부..(조정 불가로 설정 - NoResize)
            Left = owner.Left + 96;
            Top = owner.Top + 96;                                   //다이얼로그 창을 만든 윈도우의 Left 96 Top 96 의 위치에 위치시킴

            //윈도우 Content를 위한 스택 패널 생성
            StackPanel stackMain = new StackPanel();
            Content = stackMain;                                    //해당 다이얼로그와 StackPanel을 연결함.

            //프로그램 명을 위한 텍스트 블록 생성
            TextBlock txtblk = new TextBlock();                      //텍스트 블록 객체 생성
            txtblk.Text = strTitle + "Version : " + strVersion + "\r\n" + strCopyright;         //텍스트 블록 내의 내용
            txtblk.FontFamily = new FontFamily("Times New Roman");   //폰트 설정
            txtblk.FontSize = 32;                                    //24포인트로 폰트 크기 설정
            txtblk.FontStyle = FontStyles.Italic;                    //폰트 스타일 설정
            txtblk.Margin = new Thickness(24);                       //여백 설정
            txtblk.HorizontalAlignment = HorizontalAlignment.Center; //텍스트 블록의 위치

            stackMain.Children.Add(txtblk);                          //StackPanel에 텍스트 블록 추가

            //웹사이트 링크를 위한 텍스트 블록 생성
            Run run = new Run("http://cyworld.com/1988_01_29");      //웹사이트 링크 주소 설정
            Hyperlink link = new Hyperlink(run);                     //하이퍼링크 설정
            link.Click += LinkOnClick;                               //링크를 클릭 했을 때 이벤트 발생!
            txtblk = new TextBlock(link);                            //하이퍼링크를 위한 텍스트 블록 생성
            txtblk.FontSize = 20;                                    //웹사이트 링크의 폰트 사이즈
            txtblk.HorizontalAlignment = HorizontalAlignment.Center; //웹사이트 링크의 위치

            stackMain.Children.Add(txtblk);                          //StackPanel에 추가함

            //OK버튼 생성
            Button btn = new Button();
            btn.Content = "OK";
            btn.IsDefault = true;                                   //기본 단추로 설정
            btn.IsCancel = true;                                    //취소 단추인지 설정.. ESC로도 활성화 가능!
            btn.HorizontalAlignment = HorizontalAlignment.Center;   //정렬은 중앙에
            btn.MinWidth = 48;                                      //최소 48픽셀의 가로 크기를 가진다.
            btn.Margin = new Thickness(24);                         //여백은 24포인트
            btn.Click += OkOnClick;                                 //OK를 클릭 했을 때 설정

            stackMain.Children.Add(btn);                            //스택 메인에 추가함

            btn.Focus();                                            //최초 버튼이 포커스를 가지고 있게 설정함.
        }
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:68,代码来源:AboutDialog.cs


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