本文整理汇总了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;
}