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

Call Command of ViewModel from DataTemplate

$
0
0

Hey,

I am stuck on a binding problem here.

I created a bindable layout which is inside a control template:

<ContentView x:Name="SettingsMenu" ControlTemplate="{StaticResource HeaderTemplate}" AbsoluteLayout.LayoutBounds="0.5,0.5,1,1" AbsoluteLayout.LayoutFlags="All"> <ScrollView Orientation="Vertical" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"> <StackLayout x:Name="SettingsStack" BindableLayout.ItemsSource="{Binding Settings}" BindableLayout.ItemTemplateSelector="{StaticResource SettingsSelectorTemplate}" Orientation="Vertical" Spacing="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" /> </ScrollView> </ContentView>

What I want to do is call a command inside the view model. The call is inside an item template selector as a resource dictionary inside App.xml

<ResourceDictionary> <DataTemplate x:Key="PlaceholderSettingsTemplate"> ### SOME STUFF </DataTemplate> <DataTemplate x:Key="HeaderSettingsTemplate"> ### SOME STUFF <Grid.GestureRecognizers> <TapGestureRecognizer Tapped="ButtonClick" Command="{Binding BindingContext.SettingsTap, Source={x:Reference SettingsPage}}" CommandParameter="{Binding}" /> ########## <--------- WHAT TO USE FOR SOURCE? </Grid.GestureRecognizers> </Grid> </DataTemplate> <data:SettingsSelector x:Key="SettingsSelectorTemplate" Placeholder="{StaticResource PlaceholderSettingsTemplate}" Heading="{StaticResource HeaderSettingsTemplate}" Content="{StaticResource ContentSettingsTemplate}" /> </ResourceDictionary>

Before I moved it inside a resource dictionary in the App.xml file, I simply used the x:Name of the Parent Contentview. But: I can't reference it by name anymore because I moved it into a resource dictionary inside App.xml.

Now, the answer may be trivial but I just can't find a solution.

Any help is appreciated.

Kind regards


Viewing all articles
Browse latest Browse all 89864

Trending Articles



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