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

Event handlers defined inside DataTemplate are missed issue

$
0
0

Hello

I am creating a Xamarin Forms application. Now it works fine on Android and Windows Phone but I have problems with running it on iOS.

<ContentPage.Content>
    <StackLayout>
        <Label Text="{Binding Title}"></Label>
        <ListView x:Name="FeedsListView" ItemsSource="{Binding Feed}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <ViewCell.View>
                            <StackLayout Orientation="Horizontal" >
                                <Button BackgroundColor="Red" Clicked="SaveFeedClicked">Save</Button>
                                <StackLayout>
                                    <StackLayout.GestureRecognizers>
                                        <TapGestureRecognizer Tapped="OpenFeedClicked"/>
                                    </StackLayout.GestureRecognizers>
                                    <Label Text="{Binding Title}" TextColor="Yellow"></Label>
                                    <Label Text="{Binding Description}"></Label>
                                    <Label Text="{Binding PubDate}" Font="Small" TextColor="Blue"></Label>
                                </StackLayout>
                            </StackLayout>
                        </ViewCell.View>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
        <Button x:Name="btnArchive" Clicked="openArchive_Clicked"  Text="Archive"></Button>
    </StackLayout>
</ContentPage.Content>

Here I have a ListView with defined DataTemplate. Inside I have event handlers defined
Clicked="SaveFeedClicked"
and
Tapped="OpenFeedClicked"

    public partial class FeedsScreen
    {
            void SaveFeedClicked(object sender, EventArgs e)
            {
                    // code...
            }

            void OpenFeedClicked(object sender, EventArgs e)
            {
                    // code...
            }

            void openArchive_Clicked(object sender, EventArgs e)
            {
                    // code...
            }
     }

And defined NavigationPage:

    public static Page GetMainPage()
    {
        return new NavigationPage(new FeedsScreen());
    }

AppDelegate.cs:

    window.RootViewController = ContentManager.GetMainPage().CreateViewController();
    window.MakeKeyAndVisible();

Then, when I launching application on iOS simulator I get following exception:
http://cs619231.vk.me/v619231277/167cf/UCBGahgUF7U.jpg

Clicked="openArchive_Clicked" works fine.
I prefer find XAML solution rather than code-behind.
So, please help to fix this issue. I appreciate any prompt.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>