Getting Instances via Factory Methods
With the x:FactoryMethod
keyword in XAML2009, you can get an instance of a class that doesn’t have any public constructors. x:FactoryMethod
enables you to specify any public static method that returns an instance of the desired type. For example, the following XAML uses a Guid
instance returned by the static Guid.NewGuid
method:
<Label xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" Background="Orange" FontSize="20"> <sys:Guid x:FactoryMethod="sys:Guid.NewGuid"/> </Label>
When x:FactoryMethod
is used with x:Arguments
, the arguments are ...
Get XAML Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.