-
-
Save abock/c14226892f2f808a14c4265dfc07bbe9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSKeyValueBinding.cs | |
// | |
// Author: | |
// Aaron Bockover <abock@xamarin.com> | |
// | |
// Copyright 2016 Microsoft. All rights reserved. | |
using System; | |
using System.Runtime.InteropServices; | |
using Foundation; | |
using ObjCRuntime; | |
namespace AppKit | |
{ | |
static class NSKeyValueBinding | |
{ | |
[DllImport (Constants.ObjectiveCLibrary, EntryPoint = "objc_msgSend")] | |
static extern void void_objc_msgSend_IntPtr_IntPtr_IntPtr_IntPtr ( | |
IntPtr handle, IntPtr sel, IntPtr binding, IntPtr observable, IntPtr keyPath, IntPtr options); | |
static readonly IntPtr bindToObjectWithKeyPathOptionsSel = Selector.GetHandle ( | |
"bind:toObject:withKeyPath:options:"); | |
public static void Bind ( | |
this NSObject obj, | |
NSString binding, | |
NSObject observable, | |
string keyPath, | |
NSDictionary options = null) | |
{ | |
if (obj == null) | |
throw new ArgumentNullException (nameof (obj)); | |
if (binding == null) | |
throw new ArgumentNullException (nameof (binding)); | |
if (observable == null) | |
throw new ArgumentNullException (nameof (observable)); | |
if (keyPath == null) | |
throw new ArgumentNullException (nameof (keyPath)); | |
var keyPathNative = NSString.CreateNative (keyPath); | |
try { | |
void_objc_msgSend_IntPtr_IntPtr_IntPtr_IntPtr ( | |
obj.Handle, | |
bindToObjectWithKeyPathOptionsSel, | |
binding.Handle, | |
observable.Handle, | |
keyPathNative, | |
options == null ? IntPtr.Zero : options.Handle); | |
} finally { | |
NSString.ReleaseNative (keyPathNative); | |
} | |
} | |
public static readonly NSString SelectedIndexBinding = Dlfcn.GetStringConstant ( | |
Dlfcn.dlopen (Constants.AppKitLibrary, 0), | |
"NSSelectedIndexBinding"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment