本文整理汇总了C#中System.Windows.Window.SetResourceReference方法的典型用法代码示例。如果您正苦于以下问题:C# Window.SetResourceReference方法的具体用法?C# Window.SetResourceReference怎么用?C# Window.SetResourceReference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Window
的用法示例。
在下文中一共展示了Window.SetResourceReference方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnApplicationStartup
private void OnApplicationStartup(object sender, StartupEventArgs e)
{
Application.Current.Startup -= OnApplicationStartup;
var window = new Window()
{
DataContext = new ClearMineViewModel(),
WindowStartupLocation = WindowStartupLocation.CenterScreen
};
window.SetResourceReference(Window.StyleProperty, "MainWindowStyle");
window.SetResourceReference(Window.ContentTemplateProperty, typeof(ClearMineViewModel));
window.Show();
// Put data initialization after dialog shows up to speed up the dialog showing.
InitializeMenu();
}
示例2: OpenTopLevelView
/// <summary>
/// Opens the top level view in a separate window.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="messageBoxResult">The message box result.</param>
/// <param name="viewResult">The view result.</param>
/// <returns>True if successfully opened</returns>
private bool OpenTopLevelView(RequestContext context, MessageBoxResult messageBoxResult, ViewResult viewResult)
{
if (messageBoxResult != null && string.IsNullOrEmpty(viewResult.ViewIconResourceKey))
viewResult.ViewIconResourceKey = messageBoxResult.ModelMessageBox.IconResourceKey;
//Brush iconBrush = Brushes.Transparent;
//if (!string.IsNullOrEmpty(viewResult.ViewIconResourceKey))
// try
// {
// var resource = Application.Current.FindResource(viewResult.ViewIconResourceKey);
// if (resource != null)
// iconBrush = (Brush) resource;
// }
// catch
// {
// iconBrush = Brushes.Transparent;
// }
// If we respect local views and the view is in fact a local view, and we have a normal view already open, then we open it in a local way only.
if (viewResult.ViewScope == ViewScope.Local && HandleLocalViewsSpecial && SelectedNormalView > -1)
{
var selectedView = NormalViews[SelectedNormalView];
if (selectedView == null) return false;
selectedView.LocalViews.Add(viewResult);
if (viewResult.MakeViewVisibleOnLaunch)
selectedView.SelectedLocalViewIndex = selectedView.LocalViews.Count - 1;
return true;
}
//Need to make sure we do not open more than allowed - Popups should not close underlying views.
if (viewResult.ViewLevel != ViewLevel.Popup && MaximumTopLevelViewCount > -1)
{
var inplaceTopLevelviews = TopLevelViews.Where(v => v.TopLevelWindow == null).ToList();
while (inplaceTopLevelviews.Count + 1 > MaximumTopLevelViewCount)
{
CloseViewForModel(inplaceTopLevelviews[0].Model);
inplaceTopLevelviews.RemoveAt(0);
}
}
TopLevelViews.Add(viewResult);
if (viewResult.MakeViewVisibleOnLaunch && !(TopLevelViewLaunchMode == ViewLaunchMode.Popup || (TopLevelViewLaunchMode == ViewLaunchMode.InPlaceExceptPopups && viewResult.ViewLevel == ViewLevel.Popup)))
{
SelectedTopLevelView = TopLevelViews.Count - 1;
SelectedTopLevelViewResult = SelectedTopLevelView > -1 ? TopLevelViews[SelectedTopLevelView] : null;
if (viewResult.View != null)
if (!FocusHelper.FocusFirstControlDelayed(viewResult.View))
FocusHelper.FocusDelayed(viewResult.View);
}
TopLevelViewCount = TopLevelViews.Count;
if (TopLevelViewLaunchMode == ViewLaunchMode.Popup || (TopLevelViewLaunchMode == ViewLaunchMode.InPlaceExceptPopups && viewResult.ViewLevel == ViewLevel.Popup))
{
var window = new Window
{
Title = viewResult.ViewTitle,
Content = viewResult.View,
DataContext = viewResult.Model,
WindowStartupLocation = WindowStartupLocation.CenterScreen,
Owner = this
};
window.SetBinding(TitleProperty, new Binding("ViewTitle") { Source = viewResult });
// Setting the size strategy
var strategy = SimpleView.GetSizeStrategy(viewResult.View);
switch (strategy)
{
case ViewSizeStrategies.UseMinimumSizeRequired:
window.SizeToContent = SizeToContent.WidthAndHeight;
break;
case ViewSizeStrategies.UseMaximumSizeAvailable:
window.SizeToContent = SizeToContent.Manual;
window.Height = SystemParameters.WorkArea.Height;
window.Width = SystemParameters.WorkArea.Width;
break;
case ViewSizeStrategies.UseSuggestedSize:
window.SizeToContent = SizeToContent.Manual;
window.Height = SimpleView.GetSuggestedHeight(viewResult.View);
window.Width = SimpleView.GetSuggestedWidth(viewResult.View);
break;
}
viewResult.TopLevelWindow = window;
if (context.Result is MessageBoxResult) window.SetResourceReference(StyleProperty, "CODE.Framework.Wpf.Mvvm.Shell-TopLevelMessageBoxWindowStyle");
else window.SetResourceReference(StyleProperty, "CODE.Framework.Wpf.Mvvm.Shell-TopLevelWindowStyle");
if (viewResult.View != null)
foreach (InputBinding binding in viewResult.View.InputBindings)
window.InputBindings.Add(binding);
//.........这里部分代码省略.........
示例3: OpenNormalViewInWindow
/// <summary>
/// Opens a normal view in a separate window.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="viewResult">The view result.</param>
private static void OpenNormalViewInWindow(RequestContext context, ViewResult viewResult)
{
var window = new Window
{
Title = viewResult.ViewTitle,
SizeToContent = SizeToContent.WidthAndHeight,
Content = viewResult.View,
DataContext = viewResult.Model,
WindowStartupLocation = WindowStartupLocation.CenterScreen
};
window.SetBinding(TitleProperty, new Binding("ViewTitle") {Source = viewResult});
var simpleView = viewResult.View as SimpleView;
if (simpleView != null)
if (SimpleView.GetSizeStrategy(simpleView) == ViewSizeStrategies.UseMaximumSizeAvailable)
window.SizeToContent = SizeToContent.Manual;
viewResult.TopLevelWindow = window;
if (context.Result is MessageBoxResult) window.SetResourceReference(StyleProperty, "CODE.Framework.Wpf.Mvvm.Shell-TopLevelMessageBoxWindowStyle");
else window.SetResourceReference(StyleProperty, "CODE.Framework.Wpf.Mvvm.Shell-NormalLevelWindowStyle");
if (viewResult.IsModal) window.ShowDialog();
else window.Show();
}