Search code examples
xamluno-platform

Uno Platform Material Card Event Handler


I am trying to figure out the Click event handler for a Uno Material Card. My goal is to have the user tap on the card- and it will navigate them to another page. I checked in the source code- card.cs and card.xaml and tried implementing the methods in there- but it did not work. I tried implementing a Pressed action- but it would not compile. I have also tried OnChecked, Checked as well. What method do I need to implement in order for the action to be fired? Thank you for your help!

//Xaml
<material:Card HeaderContent="Outlined card2"
               SubHeaderContent="With title and subtitle only"
               Style="{StaticResource MaterialOutlinedCardStyle}"
               Click="testPageClick">
            <material:Card.HeaderContentTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding}"
                    Margin="16,14,16,0"
                    Style="{ThemeResource MaterialHeadline6}" />
                </DataTemplate>
            </material:Card.HeaderContentTemplate>
            <material:Card.SubHeaderContentTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding}"
                    Margin="16,0,16,14"
                    Style="{ThemeResource MaterialBody2}" />
                </DataTemplate>
            </material:Card.SubHeaderContentTemplate>
        </material:Card>
//Handler
        private void testPageClick(object sender, RoutedEventArgs e)
        {

            this.Frame.Navigate(typeof(testPage));

        }

Solution

  • After more experimentation- I found four events that work. They are Tapped, PointerPressed, PointerReleased, and PointerExited. They all have a slightly different effect when used- but the end result is the same. Hopefully this helps someone else that is stumped.