private Binding CreateBinding(IResourceContext context, BindingProxy proxy)
 {
     return(new Binding
     {
         Source = proxy,
         Path = new PropertyPath(BindingProxy.ValueProperty),
         Converter = GetValueConverter(context),
         Mode = BindingMode.OneWay
     });
 }
        public override BindingBase ProvideBinding(IResourceContext context)
        {
            var key = new DynamicResourceKey(ResourceKey);

            if (context.TryFindResource(key) is BindingProxy proxy)
            {
                return(CreateBinding(context, proxy));
            }

            proxy = new BindingProxy();
            context.AddResource(key, proxy);
            proxy.Value = new DynamicResourceExtension(ResourceKey).ProvideValue(new Target(context));
            return(CreateBinding(context, proxy));
        }
Esempio n. 3
0
        public static BindingProxy GetValue(this IValueProvider valueProvider, IResourceContext context)
        {
            var proxy = new BindingProxy();
            var value = valueProvider.ProvideValue(context);

            if (value is BindingBase binding)
            {
                BindingOperations.SetBinding(proxy, BindingProxy.ValueProperty, binding);
            }
            else
            {
                proxy.Value = value;
            }

            return(proxy);
        }