Advertisement
jlind0

Untitled

Jan 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Markup;
  7. using System.Net.Http;
  8. using System.Windows.Data;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.ComponentModel;
  12.  
  13. namespace run.Transformation.Xaml
  14. {
  15.     public class ApiConnection : DependencyObject
  16.     {
  17.         public BindingBase Uri
  18.         {
  19.             get { return GetValue(UriProperty) as BindingBase; }
  20.             set { SetValue(UriProperty, value); }
  21.         }
  22.         public string Value
  23.         {
  24.             get { return GetValue(ValueProperty) as string; }
  25.             set { SetValue(ValueProperty, value); }
  26.         }
  27.         public static readonly DependencyProperty UriProperty = DependencyProperty.Register(nameof(Uri), typeof(BindingBase), typeof(ApiConnection));
  28.         public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(nameof(Value), typeof(string), typeof(ApiConnection));
  29.     }
  30.     [MarkupExtensionReturnType(typeof(string))]
  31.     public class StringApiBinding : MarkupExtension
  32.     {
  33.         public BindingBase Endpoint { get; set; }
  34.         public override object ProvideValue(IServiceProvider serviceProvider)
  35.         {
  36.             IProvideValueTarget provider = (IProvideValueTarget)serviceProvider.GetService(typeof(IProvideValueTarget));
  37.             ApiConnection connection = new ApiConnection();
  38.  
  39.             BindingOperations.SetBinding(connection, ApiConnection.UriProperty, Endpoint);
  40.             Binding binding = new Binding("Value");
  41.             BindingOperations.SetBinding(connection, ApiConnection.ValueProperty, binding);
  42.             return binding.ProvideValue(serviceProvider);
  43.         }
  44.        
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement