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


C# Window.MoveFocus方法代码示例

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


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

示例1: EnsureWindow

        private static Window EnsureWindow(object viewModel, object view, bool asChildWindow, bool asDialog)
        {
            var window = view as Window;
            if (window == null)
            {
                window = new Window
                {
                    Content = view ?? viewModel,
                    SizeToContent = SizeToContent.WidthAndHeight,
                };
                window.Loaded += (sender, e) => window.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));

                if (asDialog)
                {
                    window.ResizeMode = ResizeMode.NoResize;

                    // According to Windows Style Guides: Model dialog should not have system menu.
                    WindowsHelper.SetShowIcon(window, false);
                }
            }

            var hasDisplayName = viewModel as IDisplayName;
            if (hasDisplayName != null
                && window.ReadLocalValue(Window.TitleProperty) == DependencyProperty.UnsetValue // No local value.
                && BindingOperations.GetBinding(window, Window.TitleProperty) == null)          // No binding.
            {
                // Bind Window.Title to ViewModel.DisplayName.
                var binding = new Binding("DisplayName");
                window.SetBinding(Window.TitleProperty, binding);
            }

            var owner = InferOwnerOf(window);
            if (owner != null && asChildWindow)
            {
                window.ShowInTaskbar = false;
                window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                window.Owner = owner;
            }
            else
            {
                window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            }

            var hasDialogResult = viewModel as IDialogResult;
            if (asDialog && hasDialogResult != null)
            {
                var behaviors = Interaction.GetBehaviors(window);
                if (!behaviors.OfType<DialogResultBehavior>().Any())
                {
                    // Bind Window.DialogResult to viewModel.DialogResult using a behavior.
                    var dialogResultBehavior = new DialogResultBehavior();
                    var binding = new Binding("DialogResult") { Mode = BindingMode.TwoWay };
                    BindingOperations.SetBinding(dialogResultBehavior, DialogResultBehavior.DialogResultProperty, binding);
                    behaviors.Add(dialogResultBehavior);
                }
            }

            return window;
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:59,代码来源:WindowManager.cs


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