xamarin - Can I set the font size of a button inside the <Button> tag directly? -


i have code:

<button x:name="correctbutton" heightrequest="60" horizontaloptions="fillandexpand" verticaloptions="startandexpand">    <button.fontsize>        <onplatform x:typearguments="x:double" x:key="windowbackgroundtable">            <on platform="android" value="20" />            <on platform="ios" value="25" />        </onplatform>      </button.fontsize> </button> 

is there way platform specific sizes can set without have

<button.fontsize> 

no, need kind of code if want make difference per platform.

normally, set this: <button fontsize="25" x:name="correctbutton" heightrequest="60" horizontaloptions="fillandexpand" verticaloptions="startandexpand" />

but cannot distinguish values platforms. do, anto mentioned, create style , set values, per platform, there. code bit cleaner in page itself, idea remains same.

to this, in app.xaml, add style:

<application.resources>     <resourcedictionary>         <onplatform x:typearguments="x:double" x:key="windowbackgroundtable">             <on platform="android" value="20" />             <on platform="ios" value="25" />         </onplatform>          <style targettype="button">             <setter property="fontsize" value="{dynamicresource windowbackgroundtable}" />         </style>     </resourcedictionary> </application.resources> 

and remove fontsize button. this, implicit, every button in app styled.

if not want, add x:key property style tag, so: <style x:key="buttonstyle" targettype="button">.

and edit button this: <button style="{staticresource buttonstyle}" text="welcome xamarin forms!" verticaloptions="center" horizontaloptions="center" />


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -