Skip to content

Commit

Permalink
Added the ability to do code behind bindings in Forms
Browse files Browse the repository at this point in the history
  • Loading branch information
mellson committed Aug 15, 2017
1 parent f05dad9 commit fbd3090
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
5 changes: 3 additions & 2 deletions MvvmCross-Forms/MvvmCross.Forms/Core/IMvxContentPage.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using MvvmCross.Core.ViewModels;
using MvvmCross.Binding.BindingContext;
using MvvmCross.Core.ViewModels;
using MvvmCross.Core.Views;

namespace MvvmCross.Forms.Core
{
public interface IMvxContentPage : IMvxView
public interface IMvxContentPage : IMvxView, IMvxBindingContextOwner
{
MvxViewModelRequest Request { get; set; }
}
Expand Down
29 changes: 26 additions & 3 deletions MvvmCross-Forms/MvvmCross.Forms/Core/MvxContentPage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MvvmCross.Core.ViewModels;
using MvvmCross.Binding.BindingContext;
using MvvmCross.Core.ViewModels;
using Xamarin.Forms;

namespace MvvmCross.Forms.Core
Expand All @@ -7,8 +8,30 @@ public class MvxContentPage : ContentPage, IMvxContentPage
{
public object DataContext
{
get { return BindingContext; }
set { BindingContext = value; }
get
{
return BindingContext.DataContext;
}
set
{
base.BindingContext = value;
BindingContext.DataContext = value;
}
}

private IMvxBindingContext _bindingContext;
public new IMvxBindingContext BindingContext
{
get
{
if (_bindingContext == null)
BindingContext = new MvxBindingContext(base.BindingContext);
return _bindingContext;
}
set
{
_bindingContext = value;
}
}

public IMvxViewModel ViewModel
Expand Down

0 comments on commit fbd3090

Please sign in to comment.