xaml - Xamarin.Forms - x:Reference 2nd level -


i'm working in new contentpage application , have controls datatemplates.

i use command in contentpage's viewmodel in 1 of datatemplates, i'm not sure how right reference work properly. here's xaml code:

<?xml version="1.0" encoding="utf-8"?> <contentpage      xmlns="http://xamarin.com/schemas/2014/forms"      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"      x:class="maverickmobileonline.imageslistingpage"      --many namespace references--     >       <contentpage.resources>         <resourcedictionary>           <c:itemtappedeventargsconverter x:key="itemtappedconverter" />           <c:itemappearingeventargsconverter x:key="itemappearingconverter" />           <c:booleannegationconverter x:key="not" />         </resourcedictionary>     </contentpage.resources>      <stacklayout spacing="0">         <commonviews:maincustomnavbar minimumheightrequest="120" />           <controls:pulltorefreshlayout           x:name = "layout"            refreshcommand="{binding btn_reload_businesses_images_click}"               isenabled = "true"                   isrefreshing="{binding path=is_businesses_loading}" >             <scrollview             x:name = "scrollview"             horizontaloptions="fillandexpand"             verticaloptions="fillandexpand">                 <templates:itemsstack                      padding="0"                      margin="0,10,0,10"                     x:name="itmstack"                     backgroundcolor="white"                       itemssource="{binding path=photos_list}">                  <templates:itemsstack.itemtemplate>                     <datatemplate>                          <artina:gridoptionsview                                   padding="10,0"                                  columnspacing="10"                                  rowspacing="10"                                  verticaloptions="fill"                                  heightrequest="120"                                 columncount="3"                                 rowcount="1"                                 itemssource="{binding path=.}">                                  <artina:gridoptionsview.itemtemplate>                                     <datatemplate>                                          <contentview                                              xmlns="http://xamarin.com/schemas/2014/forms"                                              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"                                              x:class="maverickmobileonline.galleryimageitemtemplate"                                             xmlns:ffimageloading="clr-namespace:ffimageloading.forms;assembly=ffimageloading.forms"                                             xmlns:fftransformations="clr-namespace:ffimageloading.transformations;assembly=ffimageloading.transformations">                                              <contentview.content>                                                 <ffimageloading:cachedimage                                                     fadeanimationenabled="true"                                                      aspect="aspectfill"                                                     verticaloptions="fillandexpand"                                                      horizontaloptions="fillandexpand"                                                      loadingplaceholder="advertising_photo_placeholder.png"                                                     source="{binding path=image_medium}" />                                             </contentview.content>                                              <contentview.gesturerecognizers>                                                 <tapgesturerecognizer                                                      -- here! --                                                      command="{binding source={x:reference x}, path=bindingcontext.command_name}"                                                      commandparameter="{binding image_medium}"                                                 />                                             </contentview.gesturerecognizers>                                          </contentview>                                      </datatemplate>                                 </artina:gridoptionsview.itemtemplate>                             </artina:gridoptionsview>                      </datatemplate>                 </templates:itemsstack.itemtemplate>             </templates:itemsstack>            </scrollview>         </controls:pulltorefreshlayout>       </stacklayout>  </contentpage> 

please take @ code after mark "-- here! --".

ps: i'm refining layout on order improve performance.

any appreciated.

update:

viewmodel:

public relaycommand<string> btn_image_tap_preview {         {         return new relaycommand<string>(             openimagepreview         );     } }  //* image tap private async void openimagepreview(string url) {     //* code } 

updated xaml:

<stacklayout x:name="mainstack" spacing="0">         <commonviews:maincustomnavbar minimumheightrequest="120" /> ....  <contentview.gesturerecognizers>    <tapgesturerecognizer command="{binding source={x:reference mainstack}, path=bindingcontext.btn_image_tap_preview}"                           commandparameter="{binding image_medium}" />  </contentview.gesturerecognizers> 

i'm debugging can't reach viewmodel's command.

you can use x:reference , take binding context of layout or element content page stacklayout. since binding context viewmodel of page have command looking @ first level itself. can directly use it.

<stacklayout x:name="mystacklayout" spacing="0">         <commonviews:maincustomnavbar minimumheightrequest="120" /> ....  <contentview.gesturerecognizers>    <tapgesturerecognizer command="{binding source={x:reference mystacklayout}, path=bindingcontext.command_name}"                           commandparameter="image_medium" />  </contentview.gesturerecognizers> 

or can set binding context tapgesture

<tapgesturerecognizer bindingcontext="{binding source={x:reference mystacklayout.bindingcontext}}" command="{binding command_name}" 

datatemplates not seem work x:reference prior v1.4.4, can read more in forum post - x:reference not working?. implementation in newer version can seen in answer here. if interested bugzilla issue fixed here.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -