Reputation: 159
I have created a native ViewCellRenderer for view cell that is being used in list view For UWP by following Microsoft article Customizing View Cell. The article explains how to create bindable properties for a view cell that can be displayed using the native controls. What I want is to be able to create a bindable event handler so that I can bind this event with native UWP code say Tapped event of Textblock.
Example- On the tapped event of Textblock 'Name' i want to navigate to some another page. The navigation logic is written inside the view model for the page where I am using the list view with custom view cell. How can I create a bindable event handler in custom view cell so that I could bind it with the Tapped event of native code.
Upvotes: 1
Views: 235
Reputation: 32775
I found the similar case in Xamarin. And our team member has replied, For your requirement, the key point is using XamlBehaviors
to bind TextBlock's Tapped
event with the command that defined in the custom view cell.
Xaml
<Application.Resources>
<ResourceDictionary>
<DataTemplate x:Key="ListViewItemTemplate">
<Grid>
<TextBlock Text="{Binding TextName}" >
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Tapped">
<core:InvokeCommandAction Command="{Binding TappedCommand}"/>
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</TextBlock>
</Grid>
</DataTemplate>
</ResourceDictionary>
</Application.Resources>
Then you could invoke navigate action in TappedCommand
method.
Upvotes: 1