mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-04 09:06:04 +02:00
* add toc/bread changes * add xaml-services * add ported wpf content * add xaml-services info to docfx * Fix links 1 * Fix links 2 * Fix links 3 * Fix links 4 * Fix links 5 * Fix links 6 * Fix links 7 * Fix xaml-services link * Fix snippets 1 * Fix snippets 2 * adjust breadcrumb and toc * remove preserve-view from breadcrumbs * add empty view to toc item xaml * update include * remove contextual toc for vs article :(
56 lines
2.8 KiB
Markdown
56 lines
2.8 KiB
Markdown
---
|
|
title: "x:FactoryMethod Directive"
|
|
ms.date: "03/30/2017"
|
|
helpviewer_keywords:
|
|
- "XAML. x:FactoryMethod directive [XAML Services]"
|
|
- "FactoryMethod directive in XAML [XAML Services]"
|
|
- "x:FactoryMethod directive [XAML Services]"
|
|
ms.assetid: 829bcbdf-5318-4afb-9a03-c310e0d2f23d
|
|
---
|
|
# x:FactoryMethod Directive
|
|
Specifies a method other than a constructor that a XAML processor should use to initialize an object after resolving its backing type.
|
|
|
|
## XAML Attribute Usage, no x:Arguments
|
|
|
|
```xaml
|
|
<object x:FactoryMethod="methodname"...>
|
|
...
|
|
</object>
|
|
```
|
|
|
|
## XAML Attribute Usage, x:Arguments as Element(s)
|
|
|
|
```xaml
|
|
<object x:FactoryMethod="methodname"...>
|
|
<x:Arguments>
|
|
oneOrMoreObjectElements
|
|
</x:Arguments>
|
|
</object>
|
|
```
|
|
|
|
## XAML Values
|
|
|
|
|||
|
|
|-|-|
|
|
|`methodname`|The string method name of a method that XAML processors call to initialize the instance specified as `object`. See Remarks.|
|
|
|`oneOrMoreObjectElements`|One or more object elements for objects that specify factory method parameters. Order is significant; it signifies the order in which arguments should be passed to the factory method.|
|
|
|
|
## Remarks
|
|
If `methodname` is an instance method, it cannot be qualified.
|
|
|
|
Static methods as factory methods are supported. If `methodname` is a static method, `methodname` is provided as a `typeName.methodName` combination, where `typeName` names the class that defines the static factory method. `typeName` can be prefix-qualified if referring to a type in a mapped xmlns. `typeName` can be a different type than `typeof(object)`.
|
|
|
|
The factory method must be a declared public method of the type that backs the relevant object element.
|
|
|
|
The factory method must return an instance that is assignable to the relevant object. Factory methods should never return null.
|
|
|
|
`x:Arguments` operates on a principle of best match for signatures of factory methods. Matching evaluates the parameter count first. If there is more than one possible match for a parameter count, parameter type is then evaluated and best match is determined. If there is still ambiguity after this phase of evaluation, XAML processor behavior is undefined.
|
|
|
|
The `x:FactoryMethod` element usage is not property element usage in the typical sense, because the directive markup does not reference the containing object element's type. It is expected that element usage is less common than attribute usage. `x:Arguments` (either attribute or element usage) can be used along with `x:FactoryMethod` element usage, but this is not specifically shown in the Usage sections.
|
|
|
|
`x:FactoryMethod` as an element must precede any other property elements, must precede any `x:Arguments` also provided as elements, and must precede any content/inner text/initialization text.
|
|
|
|
## See also
|
|
|
|
- [x:Arguments Directive](xarguments-directive.md)
|