本文整理汇总了C#中UltravioletContext.GetUI方法的典型用法代码示例。如果您正苦于以下问题:C# UltravioletContext.GetUI方法的具体用法?C# UltravioletContext.GetUI怎么用?C# UltravioletContext.GetUI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UltravioletContext
的用法示例。
在下文中一共展示了UltravioletContext.GetUI方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
/// <inheritdoc/>
public override void Initialize(UltravioletContext uv, Object configuration)
{
var config = (PresentationFoundationConfiguration)configuration ?? new PresentationFoundationConfiguration();
var upf = uv.GetUI().GetPresentationFoundation();
upf.BindingExpressionCompilerAssemblyName = config.BindingExpressionCompilerAssembly;
}
示例2: Control
/// <summary>
/// Initializes a new instance of the <see cref="Control"/> class.
/// </summary>
/// <param name="uv">The Ultraviolet context.</param>
/// <param name="name">The element's identifying name within its namescope.</param>
public Control(UltravioletContext uv, String name)
: base(uv, name)
{
var upf = uv.GetUI().GetPresentationFoundation();
dataSourceWrapper = upf.CreateDataSourceWrapperForControl(this);
LoadComponentRoot();
}
示例3: ExpressionCompilerState
/// <summary>
/// Initializes a new instance of the <see cref="ExpressionCompilerState"/> class.
/// </summary>
/// <param name="uv">The Ultraviolet context.</param>
/// <param name="compiler">The compiler used to produce view model code.</param>
public ExpressionCompilerState(UltravioletContext uv, CSharpCodeProvider compiler)
{
this.uv = uv;
this.compiler = compiler;
this.knownTypes = new Dictionary<String, Type>();
this.knownDefaultProperties = new Dictionary<Type, String>();
this.componentTemplateManager = (uv == null) ? null : uv.GetUI().GetPresentationFoundation().ComponentTemplates;
LoadKnownTypes(uv);
}
示例4: FromUvml
/// <summary>
/// Loads a new instance of the <see cref="DataTemplate"/> class from the specified UVML element.
/// </summary>
/// <param name="uv">The Ultraviolet context.</param>
/// <param name="root">The root element of the UVML template to load.</param>
/// <param name="cultureInfo">The <see cref="CultureInfo"/> to use when parsing values.</param>
/// <returns>The <see cref="DataTemplate"/> instance that was created from the specified UVML element.</returns>
public static DataTemplate FromUvml(UltravioletContext uv, XElement root, CultureInfo cultureInfo = null)
{
Contract.Require(uv, nameof(uv));
Contract.Require(root, nameof(root));
var dataSourceAnnotation = root.Parent?.Annotation<FrameworkTemplateNameAnnotation>();
var dataSourceWrapperName = dataSourceAnnotation?.Name;
var templatedParentType = default(Type);
var templatedObjectName = root.Name.LocalName;
var templatedObjectType = default(Type);
if (!uv.GetUI().GetPresentationFoundation().GetKnownType(templatedObjectName, out templatedObjectType))
throw new UvmlException(PresentationStrings.UnrecognizedType.Format(templatedObjectName));
var template = UvmlLoader.CreateTemplateFromXml(uv, root, templatedParentType, templatedObjectType, cultureInfo);
var instance = new DataTemplate(template, dataSourceWrapperName);
return instance;
}
示例5: FindByStylingName
/// <summary>
/// Finds the dependency property with the specified styling name.
/// </summary>
/// <param name="uv">The Ultraviolet context.</param>
/// <param name="dobj">The dependency object which is searching for a dependency property.</param>
/// <param name="owner">The name of the dependency property's containing type.</param>
/// <param name="name">The styling name of the dependency property.</param>
/// <returns>A <see cref="DependencyProperty"/> instance which represents the specified dependency property,
/// or <c>null</c> if no such dependency property exists.</returns>
public static DependencyProperty FindByStylingName(UltravioletContext uv, DependencyObject dobj, String owner, String name)
{
Contract.Require(uv, "uv");
Contract.Require(dobj, "dobj");
Contract.RequireNotEmpty(name, "name");
var type = String.IsNullOrEmpty(owner) ? dobj.GetType() : null;
if (type == null)
{
if (!uv.GetUI().GetPresentationFoundation().GetKnownType(owner, false, out type))
throw new InvalidOperationException(PresentationStrings.UnrecognizedType.Format(owner));
}
return FindByStylingName(name, type);
}
示例6: ResolveTypeFromName
/// <summary>
/// Resolves the type that corresponds to the specified UVML name.
/// </summary>
private static Type ResolveTypeFromName(UltravioletContext uv,
Type templatedParentType, Type templatedObjectType, String name)
{
if (String.Equals(name, "View", StringComparison.Ordinal))
return templatedObjectType;
var knownType = default(Type);
var placeholderAttr = templatedParentType?.GetCustomAttributes(typeof(UvmlPlaceholderAttribute), true).Cast<UvmlPlaceholderAttribute>()
.Where(x => String.Equals(name, x.Placeholder, StringComparison.Ordinal)).SingleOrDefault();
if (placeholderAttr != null)
{
knownType = placeholderAttr.Type;
}
else
{
if (!uv.GetUI().GetPresentationFoundation().GetKnownType(name, out knownType))
throw new UvmlException(PresentationStrings.UnrecognizedType.Format(name));
}
if (!templatedObjectType.IsAssignableFrom(knownType))
throw new UvmlException(PresentationStrings.TemplateTypeMismatch.Format(templatedObjectType.Name, knownType.Name));
return knownType;
}
示例7: GetMutatorTarget
/// <summary>
/// Determines whether the specified target is a dependency property, routed event, or standard property/event.
/// </summary>
private static UvmlMutatorTarget GetMutatorTarget(UltravioletContext uv,
String name, String value, Type type, out Object target, out Type targetType)
{
var upf = uv.GetUI().GetPresentationFoundation();
// If this is an attached property/event, find the owner type.
var depname = new DependencyName(name);
if (depname.IsAttached)
{
var attachedOwnerType = default(Type);
if (!upf.GetKnownType(depname.Owner, out attachedOwnerType))
throw new UvmlException(PresentationStrings.UnrecognizedType.Format(depname.Owner));
type = attachedOwnerType;
}
// Is it a dependency property?
var dprop = DependencyProperty.FindByName(depname.Name, type);
if (dprop != null)
{
target = dprop;
if (value != null && BindingExpressions.IsBindingExpression(value))
{
targetType = typeof(String);
return UvmlMutatorTarget.DependencyPropertyBinding;
}
targetType = dprop.PropertyType;
return UvmlMutatorTarget.DependencyProperty;
}
// Is it a routed event?
var revt = EventManager.FindByName(depname.Name, type);
if (revt != null)
{
target = revt;
targetType = typeof(String);
return UvmlMutatorTarget.RoutedEvent;
}
// Is it a standard property?
var clrprop = type.GetProperty(depname.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
if (clrprop != null)
{
target = clrprop;
targetType = clrprop.PropertyType;
return UvmlMutatorTarget.StandardProperty;
}
// Is it a standard event?
var clrevt = type.GetEvent(depname.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
if (clrevt != null)
{
target = clrevt;
targetType = typeof(String);
return UvmlMutatorTarget.StandardEvent;
}
throw new UvmlException(PresentationStrings.EventOrPropertyDoesNotExist.Format(depname.Name, type.Name));
}
示例8: CreateMutatorForXmlElement
/// <summary>
/// Creates a new mutator from the specified XML element.
/// </summary>
private static UvmlMutator CreateMutatorForXmlElement(UltravioletContext uv,
XElement parent, XElement element, Type templatedParentType, Type templatedObjectType, CultureInfo cultureInfo)
{
var name = element.Name.LocalName;
var value = default(UvmlNode);
var target = default(Object);
var targetType = default(Type);
var targetKind = default(UvmlMutatorTarget);
var elementChildren = element.Elements().ToList();
if (elementChildren.Any() || element.IsEmpty)
{
targetKind = GetMutatorTarget(uv,
element.Name.LocalName, null, templatedObjectType, out target, out targetType);
if (typeof(FrameworkTemplate).IsAssignableFrom(targetType))
{
if (elementChildren.Count() > 1)
throw new UvmlException(PresentationStrings.InvalidChildElements.Format(name));
var frameworkTemplateElement = elementChildren.Single();
var frameworkTemplateType = default(Type);
if (!uv.GetUI().GetPresentationFoundation().GetKnownType(frameworkTemplateElement.Name.LocalName, out frameworkTemplateType))
throw new UvmlException(PresentationStrings.UnrecognizedType.Format(frameworkTemplateElement.Name.LocalName));
if (!targetType.IsAssignableFrom(frameworkTemplateType))
throw new UvmlException(PresentationStrings.IncompatibleType.Format(targetType.Name, frameworkTemplateType.Name));
var frameworkTemplateChildren = frameworkTemplateElement.Elements().ToList();
if (frameworkTemplateChildren.Count() > 1)
throw new UvmlException(PresentationStrings.InvalidChildElements.Format(frameworkTemplateElement.Name));
var frameworkTemplateContent = frameworkTemplateChildren.SingleOrDefault();
value = CreateFrameworkTemplateUvmlNode(uv, frameworkTemplateType, frameworkTemplateContent, cultureInfo);
}
else
{
var itemType = default(Type);
if (UvmlCollectionItemMutatorBase.IsSupportedCollectionType(targetType, out itemType))
{
var items = elementChildren.Select(x => CreateTemplateFromXml(uv, x, templatedParentType, itemType, cultureInfo)).ToList();
return CreateMutatorForCollection(uv, targetKind, target, items);
}
else
{
if (elementChildren.Count() > 1)
throw new UvmlException(PresentationStrings.InvalidChildElements.Format(name));
value = CreateTemplateFromXml(uv, elementChildren.Single(), templatedParentType, targetType, cultureInfo);
}
}
}
else
{
targetKind = GetMutatorTarget(uv,
element.Name.LocalName, element.Value, templatedObjectType, out target, out targetType);
value = new UvmlLiteral(element.Value, targetType, cultureInfo);
}
return CreateMutatorForTarget(targetKind, templatedParentType, templatedObjectType, target, value);
}
示例9: Load
/// <summary>
/// Loads an instance of the <see cref="PresentationFoundationView"/> from an XML node.
/// </summary>
/// <param name="uv">The Ultraviolet context.</param>
/// <param name="uiPanel">The <see cref="UIPanel"/> that is creating the panel.</param>
/// <param name="uiPanelDefinition">The <see cref="UIPanelDefinition"/> that defines the view.</param>
/// <param name="vmfactory">A view model factory which is used to create the view's initial view model, or <see langword="null"/> to skip view model creation.</param>
/// <returns>The <see cref="PresentationFoundationView"/> that was loaded from the specified XML element.</returns>
public static PresentationFoundationView Load(UltravioletContext uv, UIPanel uiPanel, UIPanelDefinition uiPanelDefinition, UIViewModelFactory vmfactory)
{
Contract.Require(uv, nameof(uv));
Contract.Require(uiPanel, nameof(uiPanel));
Contract.Require(uiPanelDefinition, nameof(uiPanelDefinition));
var viewElement = uiPanelDefinition.ViewElement;
if (viewElement == null)
return null;
// Determine which culture to use when parsing values.
var cultureRequested = (String)uiPanelDefinition.RootElement.Attribute("Culture");
var cultureInfo = CultureInfo.GetCultureInfo(cultureRequested ?? String.Empty);
// Determine the type of view model used by this view.
var viewModelType = default(Type);
var viewModelTypeName = (String)viewElement.Attribute("ViewModelType");
if (viewModelTypeName != null)
{
viewModelType = Type.GetType(viewModelTypeName, false);
if (viewModelType == null)
throw new UvmlException(PresentationStrings.ViewModelTypeNotFound.Format(viewModelTypeName));
var viewModelWrapperAttr = viewModelType.GetCustomAttributes(typeof(ViewModelWrapperAttribute), false)
.Cast<ViewModelWrapperAttribute>().SingleOrDefault();
if (viewModelWrapperAttr != null)
{
viewModelType = viewModelWrapperAttr.WrapperType;
}
else
{
var viewModelWrapperName = PresentationFoundationView.GetDataSourceWrapperNameForView(uiPanelDefinition.AssetFilePath);
var viewModelWrapperType = uv.GetUI().GetPresentationFoundation().GetDataSourceWrapperTypeByName(viewModelWrapperName);
if (viewModelWrapperType == null)
throw new UvmlException(PresentationStrings.CannotFindViewModelWrapper.Format(viewModelWrapperName));
viewModelType = viewModelWrapperType;
}
}
// Create a UVML template which will instantiate the view.
AddUvmlAnnotations(viewModelType.Name, viewElement);
var viewTemplate = new UvmlTemplate(viewElement, typeof(PresentationFoundationView), (puv, pname) =>
{
var view = new PresentationFoundationView(puv, uiPanel, viewModelType);
var viewModel = vmfactory == null ? null : vmfactory(view);
if (viewModel != null)
{
view.SetViewModel(viewModel);
}
var root = view.LayoutRoot;
root.BeginInit();
var rootAdornerDecorator = new AdornerDecorator(puv, null);
rootAdornerDecorator.BeginInit();
root.Child = rootAdornerDecorator;
var rootGridTemplate = CreateTemplateFromXml(puv, viewElement, null, typeof(Grid), cultureInfo);
var rootGridContext = UvmlInstantiationContext.ForView(puv, view);
var rootGridTemplateInstance = (UvmlTemplateInstance)rootGridTemplate.Instantiate(puv, rootGridContext);
var rootGrid = (Grid)rootGridTemplateInstance.Finalize();
rootAdornerDecorator.Child = rootGrid;
return view;
});
// Instantiate the view template.
var viewTemplateInstance = (UvmlTemplateInstance)viewTemplate.Instantiate(uv, null);
var viewInstance = (PresentationFoundationView)viewTemplateInstance.Finalize();
var viewRoot = viewInstance.LayoutRoot;
var viewRootAdornerDecorator = (AdornerDecorator)viewRoot.Child;
viewRootAdornerDecorator.EndInit();
viewRoot.EndInit();
viewRoot.CacheLayoutParameters();
var viewInstanceViewModel = viewInstance.ViewModel;
if (viewInstanceViewModel != null)
viewInstance.Namescope.PopulateFieldsFromRegisteredElements(viewInstanceViewModel);
return viewInstance;
}
示例10: StoryboardClockPool
/// <summary>
/// Initializes a new instance of the <see cref="StoryboardClockPool"/> class.
/// </summary>
/// <param name="uv">The Ultraviolet context.</param>
private StoryboardClockPool(UltravioletContext uv)
: base(uv)
{
uv.GetUI().Updating += StoryboardClockPool_Updating;
}
示例11: LoadKnownTypes
/// <summary>
/// Loads the set of known types which are available to the compiler.
/// </summary>
/// <param name="uv">The Ultraviolet context.</param>
private void LoadKnownTypes(UltravioletContext uv)
{
if (uv != null)
{
var upf = uv.GetUI().GetPresentationFoundation();
foreach (var kvp in upf.GetKnownTypes())
knownTypes[kvp.Key] = kvp.Value;
foreach (var kvp in knownTypes)
{
String property;
if (upf.GetElementDefaultProperty(kvp.Value, out property))
knownDefaultProperties[kvp.Value] = property;
}
}
else
{
var types = from type in typeof(PresentationFoundation).Assembly.GetTypes()
let attrKnownType = type.GetCustomAttributes(typeof(UvmlKnownTypeAttribute), false).Cast<UvmlKnownTypeAttribute>().SingleOrDefault()
let attrDefaultProp = type.GetCustomAttributes(typeof(DefaultPropertyAttribute), true).Cast<DefaultPropertyAttribute>().SingleOrDefault()
where attrKnownType != null
select new { Type = type, AttrKnownType = attrKnownType, AttrDefaultProp = attrDefaultProp };
foreach (var type in types)
{
var name = type.AttrKnownType.Name ?? type.Type.Name;
knownTypes[name] = type.Type;
System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(type.Type.TypeHandle);
if (type.AttrDefaultProp != null)
knownDefaultProperties[type.Type] = type.AttrDefaultProp.Name;
}
}
}
示例12: ResolveKnownType
/// <summary>
/// Resolves the specified dependency object type name into a <see cref="Type"/> object.
/// </summary>
/// <param name="uv">The Ultraviolet context.</param>
/// <param name="name">The dependency object type name to resolve.</param>
/// <returns>The resolved <see cref="Type"/> object.</returns>
private static Type ResolveKnownType(UltravioletContext uv, String name)
{
Type type;
if (!uv.GetUI().GetPresentationFoundation().GetKnownType(name, false, out type))
{
throw new InvalidOperationException(PresentationStrings.UnrecognizedType.Format(name));
}
return type;
}
示例13: SimpleClockPool
/// <summary>
/// Initializes a new instance of the <see cref="SimpleClockPool"/> class.
/// </summary>
/// <param name="uv">The Ultraviolet context.</param>
private SimpleClockPool(UltravioletContext uv)
: base(uv)
{
uv.GetUI().Updating += SimpleClockPool_Updating;
}
示例14: InitializeContentPresenter
/// <summary>
/// Performs initialization required by instances of the <see cref="ContentPresenter"/> class.
/// </summary>
private void InitializeContentPresenter(UltravioletContext uv, Object instance, UvmlInstantiationContext context)
{
var contentPresenter = instance as ContentPresenter;
if (contentPresenter == null)
return;
if (contentPresenter.HasDefinedValue(ContentPresenter.ContentProperty) || contentPresenter.TemplatedParent == null)
return;
var alias = contentPresenter.ContentSource ?? "Content";
if (alias == String.Empty)
return;
var templateType = contentPresenter.TemplatedParent.GetType();
var templateWrapperName = PresentationFoundationView.GetDataSourceWrapperNameForComponentTemplate(templateType);
var templateWrapperType = uv.GetUI().GetPresentationFoundation().GetDataSourceWrapperTypeByName(templateWrapperName);
var dpAliasedContent = DependencyProperty.FindByName(alias, templateType);
if (dpAliasedContent != null)
{
contentPresenter.BindValue(ContentPresenter.ContentProperty, templateWrapperType,
"{{" + dpAliasedContent.Name + "}}");
}
if (!contentPresenter.HasDefinedValue(ContentPresenter.ContentStringFormatProperty))
{
var dpAliasedContentStringFormat = DependencyProperty.FindByName(alias + "StringFormat", templateType);
if (dpAliasedContentStringFormat != null)
{
contentPresenter.BindValue(ContentPresenter.ContentStringFormatProperty, templateWrapperType,
"{{" + dpAliasedContentStringFormat.Name + "}}");
}
}
}