c# - Changing FontSize dynamically in windows phone 8.1 application -
i need change application font size dynamically resource dictionary using slider control
for setting common font size created this
<x:double x:key="versefontsize">30</x:double>
and called style in textblock this
<style x:key="title_subtext" targettype="textblock"> <setter property="verticalalignment" value="center"/> <setter property="horizontalalignment" value="center"/> <setter property="foreground" value="{staticresource foregroundcolorbrush}"/> <setter property="fontweight" value="normal"/> <setter property="fontsize" value="{staticresource versefontsize}"/> <setter property="margin" value="0,5"/> </style>
now want increase or decrease font size using slider control.
i spend whole day making 1 solution , tried many, nothing works
please me guys solve issue.
dynamicresource
serves exact purpose in wpf. it's not available on windows phone.
a simple solution bind viewmodel in typical way. want viewmodel available across pages, suggest putting in application resources. sample class:
public class dynamicresources : viewmodelbase { private double versefontsize; public double versefontsize { { return versefontsize; } set { versefontsize = value; raisepropertychanged(); } } }
the example above uses mvvmlight's viewmodelbase. add main resourcedictionary
in app.xaml:
<local:dynamicresources x:key="dynamic" versefontsize="30"/>
bind in following way:
fontsize="{binding versefontsize, source={staticresource dynamic}}"
the problem bindings in setters aren't available on windows phone well. can try 1 of workarounds described here: silverlight: how use binding in setter style (or equivalent work around)
and modify value codebehind this:
private void buttonbase_onclick(object sender, routedeventargs e) { dynamicresources resources = (dynamicresources)app.current.resources["dynamic"]; resources.versefontsize = resources.versefontsize + 1; }
as resource application-wide, pages updated.
Comments
Post a Comment