Skip to content

Instantly share code, notes, and snippets.

@vvolkgang
Last active September 17, 2015 13:55
Show Gist options
  • Save vvolkgang/2bc9667c1dbc68643240 to your computer and use it in GitHub Desktop.
Save vvolkgang/2bc9667c1dbc68643240 to your computer and use it in GitHub Desktop.
ReSharper MvvmCross templates
//Parameters configuration:
//NAMESPACE: Non Editable; Macro: "Default namespace for current file"
//Name: Not Editable; Macro: "Current filename without extension"
//LayoutName: Macro: "Current filename without extension"
//name: Macro: "Value of another property with first letter lower case", Name
using Android.App;
using Android.OS;
using Cirrious.MvvmCross.Droid.Views;
namespace $NAMESPACE$
{
[Activity(Label = "$Name$", LaunchMode = LaunchMode.SingleTop, ScreenOrientation = ScreenOrientation.Portrait)]
public class $Name$ : MvxActivity
{
private $Name$Model _$name$Model;
public $Name$Model $Name$Vm => _$name$Model ?? (_$name$Model = ViewModel as $Name$Model);
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.$LayoutName$); //TODO remove View sufix
Window.SetSoftInputMode(SoftInput.StateHidden);
}
protected override void OnResume()
{
base.OnResume();
}
protected override void OnPause()
{
base.OnPause();
}
//TODO check if this is actually required. Seems hammered
public override bool OnOptionsItemSelected(IMenuItem item)
{
switch (item.ItemId)
{
case Android.Resource.Id.Home:
OnBackPressed();
return true;
}
return base.OnOptionsItemSelected(item);
}
}
}
//shortcut: mvxc
//Description: MvvmCross Command
//Parameters configuration:
//field: M-O1
//Property: Not Editable; Macro: "Value of field with first letter in upper case", field
private MvxCommand _$field$Command;
public MvxCommand $Property$Command =>_$field$Command ?? (_$field$Command = new MvxCommand($Property$));
private void $Property$()
{
throw new NotImplementedException();
}
//shortcut: mvxcc
//Description: MvvmCross Command with CanExecute
//Parameters configuration:
//field: M-O1
//Property: Not Editable; Macro: "Value of field with first letter in upper case", field
private MvxCommand _$field$Command;
public MvxCommand $Property$Command =>_$field$Command ?? (_$field$Command = new MvxCommand($Property$, Can$Property$));
private void $Property$()
{
throw new NotImplementedException();
}
private bool Can$Property$()
{
throw new NotImplementedException();
}
//Parameters configuration:
//NAMESPACE: Non Editable; Macro: "Default namespace for current file"
//Name: Not Editable; Macro: "Current filename without extension"
//LayoutName: Macro: "Current filename without extension"
//name: Macro: "Value of another property with first letter lower case", Name
using Android.OS;
using Android.Views;
using Cirrious.MvvmCross.Binding.Droid.BindingContext;
using Cirrious.MvvmCross.Droid.Fragging.Fragments;
namespace $NAMESPACE$
{
public class $Name$ : MvxFragment
{
private View _view;
private $Name$Model _$name$Model;
public $Name$Model $Name$VM => _$name$Model ?? (_$name$Model = ViewModel as $Name$Model);
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var ignored = base.OnCreateView(inflater, container, savedInstanceState);
_view = this.BindingInflate(Resource.Layout.$LayoutName$, null); //TODO Remove the View sufix
return _view;
}
}
}
//shortcut: mvxp
//Description: MvvmCross Property
//Parameters configuration:
//type: M-01
//field: M-O1
//Property: Not Editable; Macro: "Value of field with first letter in upper case", field
private $type$ _$field$;
public $type$ $Property$ {
get{return _$field$;}
set{
_$field$ = value;
RaisePropertyChanged(nameof($Property$));
}
}
//Parameters configuration:
//NAMESPACE: Non Editable; Macro: "Default namespace for current file"
//Class: Not Editable; Macro: "Current filename without extension"
using Cirrious.MvvmCross.ViewModels;
namespace $NAMESPACE$
{
public class $CLASS$ : MvxViewModel
{
$END$
public $CLASS$()
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment