Skip to content

Instantly share code, notes, and snippets.

View dbeattie71's full-sized avatar

Derek Beattie dbeattie71

  • Nebraska
  • 23:42 (UTC -05:00)
View GitHub Profile
public abstract class MvxTargetBinding2 : MvxBinding, IMvxTargetBinding
{
private readonly object _target;
protected MvxTargetBinding2(object target)
{
_target = target;
}
protected object Target
@dbeattie71
dbeattie71 / gist:18e9debee6e81bad90b7
Created March 14, 2015 02:49
MvvmCross CacheableViewModelLocator
public class CacheableViewModelLocator : MvxDefaultViewModelLocator{
public override IMvxViewModel Load(Type viewModelType, IMvxBundle parameterValues, IMvxBundle savedState)
{
if (viewModelType.GetInterfaces().Any(x=>x == typeof(ICacheableViewModel)))
{
var cache = Mvx.Resolve<IMvxMultipleViewModelCache>();
var cachedViewModel = cache.GetAndClear(viewModelType);
if (cachedViewModel == null)
cachedViewModel = base.Load(viewModelType, parameterValues, savedState);
public static void Fade (this UIView view, bool isIn, double duration = 0.3, Action onFinished = null)
{
var minAlpha = (nfloat)0.0f;
var maxAlpha = (nfloat)1.0f;
view.Alpha = isIn ? minAlpha : maxAlpha;
view.Transform = CGAffineTransform.MakeIdentity ();
UIView.Animate (duration, 0, UIViewAnimationOptions.CurveEaseInOut,
() => {
view.Alpha = isIn ? maxAlpha : minAlpha;
public class TableViewController : UITableViewController
{
static readonly NSString CellId = new NSString ("C");
readonly TableViewSource source = new TableViewSource ();
readonly List<string> rows = new List<string> ();
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
/*
Snippet Name: InlineTableViewSource
Platform: iOS
Function: A subclass of UITableViewSource that allows you to define UITableViewDataSource and UITableViewDelegate methods inline, rather than subclassing. Lets you take advantage of closures and use tableviews where you can't create subclasses, like in Xamarin Sketches (compile and reference).
Funcs/Actions are prefixed with "_", feel free to alter if this disagrees with your styling guidelines.
Usage:
var cellId = new NSString("cell");
public class CustomFragmentsPresenter : MvxFragmentsPresenter
{
public interface IMvxFragmentHostEx : IMvxFragmentHost
{
void Close(IMvxViewModel viewModel);
void ChangePresentation (MvxPresentationHint hint);
}
private IMvxNavigationSerializer _serializer;
Snippet Name: iOS Utils
Platform: Xamarin.iOS
Function: Check if running iOS 8, is phone, is tall, and envoke on UI Thread
Snippet:
public static class Utils
{
public static NSObject Invoker;
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
android:id="@+id/card_view_friend"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardCornerRadius="4dp"
card_view:cardUseCompatPadding="true">
@dbeattie71
dbeattie71 / gist:5dc4b86085b962111321
Created February 17, 2015 20:03
How to port “method_getImplementation” and “method_setImplementation” to MonoTouch?
[DllImport("/usr/lib/libobjc.dylib")]
extern static IntPtr class_getInstanceMethod(IntPtr classHandle, IntPtr Selector);
[DllImport("/usr/lib/libobjc.dylib")]
extern static IntPtr method_getImplementation(IntPtr method);
[DllImport("/usr/lib/libobjc.dylib")]
extern static IntPtr imp_implementationWithBlock(ref BlockLiteral block);
[DllImport("/usr/lib/libobjc.dylib")]
@dbeattie71
dbeattie71 / gist:2baf841b2aec86c2a16f
Last active August 29, 2015 14:15
HijackTest crash
2015-02-16 14:24:38.950 HiJackTest[4944:2813532] Attempting to JIT compile method '(wrapper managed-to-native) System.Func`3<intptr, intptr, intptr>:wrapper_aot_native (intptr&,intptr,intptr)' while running with --aot-only. See http://docs.xamarin.com/ios/about/limitations for more information.
2015-02-16 14:24:39.002 HiJackTest[4944:2813532] Moving to: <UIStatusBar: 0x154854a00; frame = (0 0; 0 20); opaque = NO; layer = <CALayer: 0x17003e4c0>>
2015-02-16 14:24:44.716 HiJackTest[4944:2813532] Unhandled managed exception: Object reference not set to an instance of an object (System.NullReferenceException)
at HiJackTest.Application.MyCapture (IntPtr block, IntPtr self, IntPtr uiView) [0x00018] in /Users/dbeattie/HijackTest/HiJackTest/Main.cs:54
at (wrapper native-to-managed) HiJackTest.Application:MyCapture (intptr,intptr,intptr)
at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr