コード例 #1
0
 public static object GetPathValue( object sourceObject, string path )
 {
   var targetObj = new GeneralUtilities();
   BindingOperations.SetBinding( targetObj, GeneralUtilities.StubValueProperty, new Binding( path ) { Source = sourceObject } );
   object value = GeneralUtilities.GetStubValue( targetObj );
   BindingOperations.ClearBinding( targetObj, GeneralUtilities.StubValueProperty );
   return value;
 }
コード例 #2
0
    public static object GetBindingValue( object sourceObject, Binding binding )
    {
      Binding bindingClone = new Binding()
      {
        BindsDirectlyToSource = binding.BindsDirectlyToSource,
        Converter = binding.Converter,
        ConverterCulture = binding.ConverterCulture,
        ConverterParameter = binding.ConverterParameter,
        FallbackValue = binding.FallbackValue,
        Mode = BindingMode.OneTime, 
        Path = binding.Path,
        StringFormat = binding.StringFormat,
        TargetNullValue = binding.TargetNullValue,
        XPath = binding.XPath
      };

      bindingClone.Source = sourceObject;

      var targetObj = new GeneralUtilities();
      BindingOperations.SetBinding( targetObj, GeneralUtilities.StubValueProperty, bindingClone );
      object value = GeneralUtilities.GetStubValue( targetObj );
      BindingOperations.ClearBinding( targetObj, GeneralUtilities.StubValueProperty );
      return value;
    }