本文整理汇总了C#中System.Windows.Controls.ContentPresenter.AddHandler方法的典型用法代码示例。如果您正苦于以下问题:C# ContentPresenter.AddHandler方法的具体用法?C# ContentPresenter.AddHandler怎么用?C# ContentPresenter.AddHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ContentPresenter
的用法示例。
在下文中一共展示了ContentPresenter.AddHandler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatePrismInstance
private object CreatePrismInstance()
{
if (this.IsInDesignMode())
{
var designTimeBlankContainer = new Grid
{
Background = new SolidColorBrush(Color.FromArgb(50, 120, 120, 120)),
};
if (_prismDataTemplate.DesignWidth.HasValue) designTimeBlankContainer.Width = _prismDataTemplate.DesignWidth.Value;
if (_prismDataTemplate.DesignHeight.HasValue) designTimeBlankContainer.Height = _prismDataTemplate.DesignHeight.Value;
var formatText = string.Format("Prism template: {0}", _prismDataTemplate.ServiceType.Name);
if (!string.IsNullOrEmpty(_prismDataTemplate.Key)) formatText += string.Format(", {0}", _prismDataTemplate.Key);
designTimeBlankContainer.Children.Add(new TextBlock
{
Text = formatText,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center,
});
return designTimeBlankContainer;
}
var view = ServiceLocator.Current.GetInstance(_prismDataTemplate.ServiceType, _prismDataTemplate.Key) as FrameworkElement;
if (view == null)
{
var error = string.Format("Service type {0} with {1} key object must be inherited from FrameworkElement",
_prismDataTemplate.ServiceType,
_prismDataTemplate.Key);
throw new ArgumentException(error);
}
var container = new ContentPresenter
{
Content = view
};
container.AddHandler(FrameworkElement.LoadedEvent, new RoutedEventHandler(LoadedRoutedEventHandler));
container.AddHandler(FrameworkElement.UnloadedEvent, new RoutedEventHandler(UnloadedRoutedEventHandler));
return container;
}