Let say i am setting my page name as x:Name="Dashboard",
but my Data template is in App.xaml resources so how do i x:Reference this now ? some thing like this
The below code is in Datatemplate inside App.xaml
<TapGestureRecognizer Command="{Binding Source={x:Reference Dashboard}, Path=BindingContext.OpenImage" />
But My ListView is in Dashboard Page .
Thanks.
Hi @NMackay
I Solved this problem like this
public class Person :ViewModelBase public RelayCommand<bool> LikeCommand => new RelayCommand<bool>((e) => { IsLiked = !e; });
and in App.XAML
<Image > <Image.GestureRecognizers> <TapGestureRecognizer Command="{Binding LikeCommand}" CommandParameter="{Binding IsLiked}" NumberOfTapsRequired="1" /> </Image.GestureRecognizers> </Image >
No need of x:Reference blah blah
Answers
I will assume that in the Page
Dashboard
, you setBindingContext
as your view model, where a Command calledOpenImage
lives.If that is true, if i would like to call
OpenImage
, from another Page, i would create apublic static viewModel
Property (which should be set to the viewModel you want to use asBindingContext
) inDashboard
, and reference it from the other Page. In that case the reference would be done as:First, in XAML add the namespace where the page you want to reference lives:
Then reference the static view model like:
@Charwaka
Seen a few ways of achieving this but generally involves a parent binding as you cannot access the Parent from the template bindingcontext.
https://forums.xamarin.com/discussion/71462/datatemplate-with-templateselector-bind-to-parent-command
Personally I think your making life difficult by insisting all your templates are in App.xaml, I explained on the other thread why this is a limitation in Xamarin Forms. If the templates have no interaction and the listitem is passed to the vm by EventToCommand ItemTapped etc then sure, put them in App.xaml.
Personally I think your making life difficult by insisting all your templates are in App.xaml,
I am just trying to find if some has already solution,i cannot assume you advise as final.always there will be a better solution.
The command is inside Observable collection Model, so how can we bind this now ASPY
You shouldn't I'm just suggesting what you want isn't supported but if you do get a solution then post it hear so we can all learn.
Actually i moved all my templates to with in Page, but still not working , but i can see get set properties are hitting while populating list
Hi @NMackay
I Solved this problem like this
and in App.XAML
No need of x:Reference blah blah
Its Resides in Person Model >.NET STANDARD 2.0 Library
and My VieModel in Another .NET STANDARD 2.0 Library
So the bound object has the command?
Yes
you can try same with some sample MvvMlight .Net Standard Project with XF 3.4
I'm sorry to say this but your statement was futile.why would i simply ask a question ? so what made me to ask to this question ?
because at deep down "command from Tap gesture was not firing " , so after i saw your answer stating x:reference would make it work .where it didnt worked both in app.xaml and in content page itself. and your much aware of this.
Ok, I give up. Good luck with your app.
Me too