xaml - Set platform specific control to only one platform in xamarin forms -


i have page contains listview , search bar control. there custom listview android. code following:

<contentpage.content>             <contentview>             <onplatform x:typearguments="view">                     <onplatform.ios>                         <stacklayout spacing="0">                             <searchbar x:name="iossearch"                                    placeholder="search"                                    textchanged="iossearchbar_ontextchanged"                                    searchbuttonpressed="onsearch" backgroundcolor="#19588f">                             </searchbar>                                <listview x:name="emplistviewios"                                       itemssource="{binding empmodel.groupeditems}"                                       itemselected="onitemselected"                                       separatorvisibility="default">                                 <listview.itemtemplate>                                     <datatemplate>                                         <viewcell>                                             <stacklayout padding="8">                                                 <stacklayout spacing="4" orientation="horizontal">                                                     <label text="{binding fullname}" fontsize="15"  textcolor="gray" linebreakmode="nowrap"/>                                                 </stacklayout>                                                 <stacklayout spacing="4" orientation="horizontal">                                                     <label text="{binding department}" fontsize="small" textcolor="#f68933" linebreakmode="wordwrap"/>                                                 </stacklayout>                                             </stacklayout>                                         </viewcell>                                     </datatemplate>                                 </listview.itemtemplate>                                         </listview>                         </stacklayout>                     </onplatform.ios>                     <onplatform.android>                         <stacklayout x:name="androidlistview">                               <searchbar x:name="droidsearch"                                    placeholder="search"                                    textchanged="droidsearchbar_ontextchanged"                                    searchbuttonpressed="onsearch" backgroundcolor="#19588f">                             </searchbar>                             <local:customlistview x:name="customlistview"                                   items="{binding empmodel.items}"                                   verticaloptions="fillandexpand" mylistitemselected="nativelistview_itemselected"                                   separatorcolor="black">                             </local:mylistview>                         </stacklayout>                     </onplatform.android>                     <onplatform.winphone>                         <stacklayout spacing="0">                         <searchbar x:name="winsearch"                                placeholder="search"                                textchanged="winsearchbar_ontextchanged"                                searchbuttonpressed="onsearch" backgroundcolor="#19588f">                         </searchbar>                              <listview x:name="emplistviewwin"                                       itemssource="{binding empmodel.groupeditems}"                                       itemselected="onitemselected"                                       separatorvisibility="default">                                 <listview.itemtemplate>                                     <datatemplate>                                         <viewcell>                                             <stacklayout padding="8">                                                 <stacklayout spacing="4" orientation="horizontal">                                                     <label text="{binding fullname}" fontsize="15"  textcolor="gray" linebreakmode="nowrap"/>                                                 </stacklayout>                                                 <stacklayout spacing="4" orientation="horizontal">                                                     <label text="{binding department}" fontsize="small" textcolor="#f68933" linebreakmode="wordwrap"/>                                                 </stacklayout>                                             </stacklayout>                                         </viewcell>                                     </datatemplate>                                 </listview.itemtemplate>                                             </listview>                         </stacklayout>                     </onplatform.winphone>                 </onplatform>             </contentview>         </contentpage.content>     </contentpage> 

as representation of data different due required custom listview android according it's layout defined. above code works fine. problem redundancy, search bar control common platform when put search bar control above <contentview> doesn't work throws exception. listview common ios , windows there custom listview android forced repeat code windows same android.

can suggest more efficient way achieve this. how can apply platform specific condition android , common windows , ios.

you share ios , winphone views using static resource:

<contentpage>   <contentpage.resourcedictionary>     <stacklayout x:key="iosorwpview">       ...     </stacklayout>   </contentpage.resourcedictionary>   <contentview>     <onplatform x:typearguments="view" ios="{staticresource iosorwpview}"                  winphone="{staticresource iosorwpview}">       <onplatform.android>         <stacklayout x:name="androidlistview">             ...         </stacklayout>       </onplatform.android>     </onplatform>   </contentview> <contentpage> 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -