本文整理汇总了C#中System.Windows.Window.ApplyTemplate方法的典型用法代码示例。如果您正苦于以下问题:C# Window.ApplyTemplate方法的具体用法?C# Window.ApplyTemplate怎么用?C# Window.ApplyTemplate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Window
的用法示例。
在下文中一共展示了Window.ApplyTemplate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: _SetWindow
private void _SetWindow(Window window)
{
Debug.Assert(null == _window);
Debug.Assert(null != window);
_window = window;
_background = _window.Background;
//if(_CaptionElement == null && !string.IsNullOrEmpty(CaptionElementName))
//{
// if (!_window.IsLoaded)
// {
// _window.SourceInitialized +=
// (sender, e) => _CaptionElement = _window.FindName(CaptionElementName) as FrameworkElement;
// } else
// {
// _CaptionElement = _window.FindName(CaptionElementName) as FrameworkElement;
// }
//}
var resourceLocater = new Uri("/" + Assembly.GetExecutingAssembly().GetName().Name + ";component/ChromelessWindowTemplate.xaml", System.UriKind.Relative);
_template = (ControlTemplate)Application.LoadComponent(resourceLocater);
Debug.Assert(null != _template);
_window.Template = _template;
// Use whether we can get an HWND to determine if the Window has been loaded.
_hwnd = new WindowInteropHelper(_window).Handle;
if (IntPtr.Zero != _hwnd)
{
_window.ApplyTemplate();
_HookCustomChrome();
}
else
{
_window.SourceInitialized += (sender, e) =>
{
_hwnd = new WindowInteropHelper(_window).Handle;
Debug.Assert(IntPtr.Zero != _hwnd);
_HookCustomChrome();
};
}
}
示例2: _SetWindow
private void _SetWindow(Window window)
{
Assert.IsNull(_window);
Assert.IsNotNull(window);
_window = window;
// There are potentially a couple funny states here.
// The window may have been shown and closed, in which case it's no longer usable.
// We shouldn't add any hooks in that case, just exit early.
// If the window hasn't yet been shown, then we need to make sure to remove hooks after it's closed.
_hwnd = new WindowInteropHelper(_window).Handle;
if (Utility.IsPresentationFrameworkVersionLessThan4)
{
// On older versions of the framework the client size of the window is incorrectly calculated.
// We need to modify the template to fix this on behalf of the user.
Utility.AddDependencyPropertyChangeListener(_window, Window.TemplateProperty, _OnWindowPropertyChangedThatRequiresTemplateFixup);
Utility.AddDependencyPropertyChangeListener(_window, Window.FlowDirectionProperty, _OnWindowPropertyChangedThatRequiresTemplateFixup);
}
_window.Closed += _UnsetWindow;
// Use whether we can get an HWND to determine if the Window has been loaded.
if (IntPtr.Zero != _hwnd)
{
// We've seen that the HwndSource can't always be retrieved from the HWND, so cache it early.
// Specifically it seems to sometimes disappear when the OS theme is changing.
_hwndSource = HwndSource.FromHwnd(_hwnd);
Assert.IsNotNull(_hwndSource);
_window.ApplyTemplate();
if (_chromeInfo != null)
{
_ApplyNewCustomChrome();
}
}
else
{
_window.SourceInitialized += (sender, e) =>
{
_hwnd = new WindowInteropHelper(_window).Handle;
Assert.IsNotDefault(_hwnd);
_hwndSource = HwndSource.FromHwnd(_hwnd);
Assert.IsNotNull(_hwndSource);
if (_chromeInfo != null)
{
_ApplyNewCustomChrome();
}
};
}
}
示例3: _SetWindow
private void _SetWindow(Window window)
{
Debug.Assert(null == _window);
Debug.Assert(null != window);
_window = window;
var resourceLocater = new Uri("/" + Assembly.GetExecutingAssembly().GetName().Name + ";component/View/Chrome/ChromelessWindowTemplate.xaml", System.UriKind.Relative);
_template = (ControlTemplate)Application.LoadComponent(resourceLocater);
Debug.Assert(null != _template);
_window.Template = _template;
// Use whether we can get an HWND to determine if the Window has been loaded.
_hwnd = new WindowInteropHelper(_window).Handle;
if (IntPtr.Zero != _hwnd)
{
_window.ApplyTemplate();
_HookCustomChrome();
}
else
{
_window.SourceInitialized += (sender, e) =>
{
_hwnd = new WindowInteropHelper(_window).Handle;
Debug.Assert(IntPtr.Zero != _hwnd);
_HookCustomChrome();
};
}
}