public override object Load(XamlReader xamlReader, IServiceProvider serviceProvider)
        {
            IXamlObjectWriterFactory settings = serviceProvider.GetService(typeof(IXamlObjectWriterFactory)) as IXamlObjectWriterFactory;

            System.Windows.Markup.IProvideValueTarget provideValueService = serviceProvider.GetService(typeof(System.Windows.Markup.IProvideValueTarget)) as System.Windows.Markup.IProvideValueTarget;

            Type propertyType = null;

            // IProvideValueTarget.TargetProperty can return DP, Attached Property or MemberInfo for clr property
            // In this case it should always be a regular clr property here.
            PropertyInfo propertyInfo = provideValueService.TargetProperty as PropertyInfo;

            if (propertyInfo != null)
            {
                propertyType = propertyInfo.PropertyType;
            }
            else
            {
                return(null);
            }

            object instance = Activator.CreateInstance(
                typeof(FuncFactory <>).MakeGenericType(propertyType.GetGenericArguments()),
                settings,
                xamlReader);

            return(Delegate.CreateDelegate(propertyType, instance, instance.GetType().GetMethod("Evaluate")));
        }
Esempio n. 2
0
        // Used to implement IProvideValueTarget Service provider.
        public static object GetTargetProperty(ObjectWriterContext xamlContext)
        {
            // If the XamlMember implements IProvideValueTarget, ask it for the TargetProperty first
            Debug.Assert(xamlContext.ParentProperty != null);

            System.Windows.Markup.IProvideValueTarget ipvt = xamlContext.ParentProperty as System.Windows.Markup.IProvideValueTarget;
            if (ipvt != null)
            {
                return(ipvt.TargetProperty);
            }

            XamlMember parentProperty = xamlContext.ParentProperty;

            //
            // We should never have a null ParentProperty here but
            // protect against null refs since we are going to dereference it
            if (parentProperty == null)
            {
                return(null);
            }

            if (parentProperty.IsAttachable)
            {
                //
                // IPVT returns the static Set method for attached properties in 3.0
                return(parentProperty.Setter);
            }
            else
            {
                //
                // This branch cover regular property (will return non null)
                // and items in a collection/diction (will return null - IPVT returns null in 3.0 for collections/dictionaries).
                return(parentProperty.UnderlyingMember);
            }
        }