コード例 #1
0
 private Binding CreateBinding(IResourceContext context, BindingProxy proxy)
 {
     return(new Binding
     {
         Source = proxy,
         Path = new PropertyPath(BindingProxy.ValueProperty),
         Converter = GetValueConverter(context),
         Mode = BindingMode.OneWay
     });
 }
コード例 #2
0
        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));
        }
コード例 #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);
        }