Skip to content

Add a bindable property to open and close the menu from a view model #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions SlideOverKit/MenuContainerPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,48 @@ public SlideMenuView SlideMenu {

public Action HidePopupAction { get; set; }

/// <summary>
/// This is a property that people using mvvm frameworks can bind to, as an alternative to explicitely calling
/// ShowMenu and HideMenu methods directly.
/// </summary>
public bool IsMenuVisible
{
get { return (bool)GetValue(IsMenuVisibleProperty); }
set { SetValue(IsMenuVisibleProperty, value); }
}

/// <summary>
/// The backing bindable property for IsMenuVisible
/// </summary>
public static readonly BindableProperty IsMenuVisibleProperty =
BindableProperty.Create("IsMenuVisible", typeof(bool), typeof(MenuContainerPage), false, BindingMode.TwoWay, null,
(bindable, oldValue, newValue) =>
{
//One property changed we hide or show the menu.
if (oldValue != newValue)
{
var thisView = (MenuContainerPage)bindable;
if ((bool)newValue) thisView.ShowMenu();
else thisView.HideMenu();
}
},
(bindable, oldValue, newValue) =>
{
// Property is changing
},
(bindable, value) =>
{
// Coerce the property
// Here we would override what the passed in value is
// And return something else - if we wanted to
return value;
},
(bindable) =>
{
// This is the default creator
return false;
});

public void ShowMenu ()
{
if (ShowMenuAction != null)
Expand Down