Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Binding an event to an EventHandler in XAML

$
0
0

Hi,

I need to bind an event to a ListView's ItemSelected EventHandler .

The ListView is defined in a XAML file, it has a ViewModel class assigned and has a binding to the properties of the ViewModel, but when it comes to binding the Behaviour of the ItemSelected I have no idea on how to do that.

¿How could I do it?

Thanks

public partial class MainView:ContentPage
    {
        public MainView()
        {
            InitializeComponent();
            BindingContext = new MainViewModel(this);
        }
    }

<ContentPage.Content>
        <Grid>
            <ListView ItemsSource="{Binding Events}" x:Name="ListViewEvents">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <ViewCell.View>
                                <StackLayout Padding="5, 5, 0, 5"
                                             Orientation="Vertical">
                                    <Label Text="{Binding Title }" Font = "{x:Static fonts:Fonts.TitleFont}" />
                                    <Label Text="{Binding Location}" Font = "{x:Static fonts:Fonts.LabelFont}"/>
                                    <Label Text="{Binding Description}"/>
                                    <Label Text="{Binding PeopleGoing, StringFormat='{0:F0} people are going'}"/>
                                </StackLayout>
                            </ViewCell.View>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </Grid>
    </ContentPage.Content>

Viewing all articles
Browse latest Browse all 58056

Trending Articles