Skip to content

Instantly share code, notes, and snippets.

@tuyen-vuduc
Last active August 10, 2018 00:34
Show Gist options
  • Save tuyen-vuduc/4b8ea23bc93a224f7657d4eb2ae9a004 to your computer and use it in GitHub Desktop.
Save tuyen-vuduc/4b8ea23bc93a224f7657d4eb2ae9a004 to your computer and use it in GitHub Desktop.
Custom control with public command
<ContentPage x:name="page">
<ListView>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<CustomControl Command="{Binding BindingContext.ShowItemCommand, Source={Reference page}}" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage>
<ContentView x:Name="view">
<Button Text="Click me!" Command="{Binding Command, Source={Reference view}" />
</ContentView>
public partial class CustomControl : ContentView {
public static readonly BindableProperty CommandProperty =
BindableProperty.Create("ICommand", typeof(ICommand), typeof(CustomControl), null, null);
public ICommand Command
{
get { return GetValue(CommandProperty); }
set { SetValue(CommandProperty, value); }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment