Skip to content

Instantly share code, notes, and snippets.

@prashantvc prashantvc/MyPage.xaml Secret
Last active Aug 29, 2015

Embed
What would you like to do?
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="ToastApp.MyPage">
<ContentPage.Content>
<Grid VerticalOptions="Start">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="{Binding Path=ToolbarHeight,Mode=TwoWay}" />
</Grid.RowDefinitions>
<Button Text="Click" Command="{Binding Fire}"/>
<Label Grid.Row="1" Text="Hello there" BackgroundColor="Red" VerticalOptions="FillAndExpand"/>
</Grid>
</ContentPage.Content>
</ContentPage>
using Xamarin.Forms;
using System.ComponentModel;
namespace ToastApp
{
public partial class MyPage : ContentPage
{
public MyPage ()
{
InitializeComponent ();
BindingContext = new MyViewModel ();
}
}
public class MyViewModel: INotifyPropertyChanged {
Command fire;
public Command Fire{
get{
return fire ?? (fire = new Command (obj => ToolbarHeight = 200));
}
}
private GridLength toolbarHeight;
public GridLength ToolbarHeight {
get {
return toolbarHeight; // Never gets called
}
set {
toolbarHeight = value;
OnPropertyChanged ("ToolbarHeight");
}
}
protected void OnPropertyChanged (string propertyName){
var handler = PropertyChanged;
if (handler!=null) {
handler (this, new PropertyChangedEventArgs (propertyName));
}
}
#region INotifyPropertyChanged implementation
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.