c# - Create FontSizeProperty -


i have custom control , want define fontsizeproperty, accessor can use:

public double fontsize {         {         return (double)getvalue(fontsizeproperty);     }     set     {         setvalue(fontsizeproperty, value);         this.textcontainer.fontsize = value;     } } 

i've tried few things, app crashes.

try 1:

public static readonly bindableproperty fontsizeproperty =         bindableproperty.create("fontsize",                                  typeof(double),                                  typeof(multilinebutton),                                  (double)label.fontsizeproperty.defaultvalue); 

exception:

unhandled exception: system.formatexception: input string not in correct format.   @ system.number.parsedouble (system.string value, system.globalization.numberstyles options, system.globalization.numberformatinfo numfmt) [0x00087] in /library/frameworks/xamarin.ios.framework/versions/10.10.0.36/src/mono/mcs/class/referencesource/mscorlib/system/number.cs:728    @ system.double.parse (system.string s, system.globalization.numberstyles style, system.globalization.numberformatinfo info) [0x00000] in /library/frameworks/xamarin.ios.framework/versions/10.10.0.36/src/mono/mcs/class/referencesource/mscorlib/system/double.cs:262    @ system.double.parse (system.string s, system.iformatprovider provider) [0x00000] in /library/frameworks/xamarin.ios.framework/versions/10.10.0.36/src/mono/mcs/class/referencesource/mscorlib/system/double.cs:245    @ xamarin.forms.xaml.typeconversionextensions.convertto (system.object value, system.type totype, system.func` 1[tresult] getconverter, system.iserviceprovider serviceprovider) [0x001f5] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\typeconversionextensions.cs:152    @ xamarin.forms.xaml.typeconversionextensions.convertto (system.object value, system.type totype, system.func`1[tresult] minforetriever, system.iserviceprovider serviceprovider) [0x00021] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\typeconversionextensions.cs:74    @ xamarin.forms.xaml.valueconverterprovider.convert (system.object value, system.type totype, system.func`1[tresult] minforetriever, system.iserviceprovider serviceprovider) [0x00000] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\valueconverterprovider.cs:15    @ xamarin.forms.setter.xamarin.forms.xaml.ivalueprovider.providevalue (system.iserviceprovider serviceprovider) [0x00062] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.core\setter.cs:34    @ xamarin.forms.xaml.applypropertiesvisitor.visit (xamarin.forms.xaml.elementnode node, xamarin.f orms.xaml.inode parentnode) [0x0004d] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\applypropertiesvisitor.cs:96    @ xamarin.forms.xaml.elementnode.accept (xamarin.forms.xaml.ixamlnodevisitor visitor, xamarin.forms.xaml.inode parentnode) [0x000b1] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\xamlnode.cs:175    @ xamarin.forms.xaml.elementnode.accept (xamarin.forms.xaml.ixamlnodevisitor visitor, xamarin.forms.xaml.inode parentnode) [0x00089] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\xamlnode.cs:172    @ xamarin.forms.xaml.fillresourcedictionariesvisitor.visit (xamarin.forms.xaml.elementnode node, xamarin.forms.xaml.inode parentnode) [0x0017e] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\fillresourcedictionariesvisitor.cs:97    @ xamarin.forms.xaml.elementnode.accept (xamarin.forms.xaml.ixamlnodevisitor visitor, xamarin.forms.xaml.inode parentnode) [0x00008] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\xamlnode.cs:165    @ xamarin.for ms.xaml.elementnode.accept (xamarin.forms.xaml.ixamlnodevisitor visitor, xamarin.forms.xaml.inode parentnode) [0x00089] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\xamlnode.cs:172    @ xamarin.forms.xaml.rootnode.accept (xamarin.forms.xaml.ixamlnodevisitor visitor, xamarin.forms.xaml.inode parentnode) [0x00054] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\xamlnode.cs:223    @ xamarin.forms.xaml.xamlloader.visit (xamarin.forms.xaml.rootnode rootnode, xamarin.forms.xaml.hydratationcontext visitorcontext) [0x0006d] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\xamlloader.cs:124    @ xamarin.forms.xaml.xamlloader.load (system.object view, system.string xaml) [0x00046] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\xamlloader.cs:76    @ xamarin.forms.xaml.xamlloader.load (system.object view, system.type callingtype) [0x0002f] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\xamlloader.cs:56    @ xamarin.forms.xaml.extensions.loadfromxaml[txaml] ( txaml view, system.type callingtype) [0x00000] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\viewextensions.cs:36    @ someproject.app.initializecomponent () [0x00001] in c:\users\some-user\project\obj\debug\someproject.app.xaml.g.cs:19    @ someproject.app..ctor () [0x00019] in c:\users\some-user\project\app.xaml.cs:68    @ someproject.ios.appdelegate.finishedlaunching (uikit.uiapplication app, foundation.nsdictionary options) [0x000bc] in c:\users\some-userproject.ios\appdelegate.cs:38    @ (wrapper managed-to-native) uikit.uiapplication:uiapplicationmain (int,string[],intptr,intptr)   @ uikit.uiapplication.main (system.string[] args, system.intptr principal, system.intptr delegate) [0x00005] in /users/builder/data/lanes/4691/d2270eec/source/xamarin-macios/src/uikit/uiapplication.cs:79    @ uikit.uiapplication.main (system.string[] args, system.string prin cipalclassname, system.string delegateclassname) [0x00038] in /users/builder/data/lanes/4691/d2270eec/source/xamarin-macios/src/uikit/uiapplication.cs:63    @ someproject.ios.application.main (system.string[] args) [0x00001] in c:\users\some-userproject.ios\main.cs:17  2017-07-28 15:04:29.748 someprojectios[8511:191052] unhandled managed exception: input string not in correct format. (system.formatexception)   @ system.number.parsedouble (system.string value, system.globalization.numberstyles options, system.globalization.numberformatinfo numfmt) [0x00087] in /library/frameworks/xamarin.ios.framework/versions/10.10.0.36/src/mono/mcs/class/referencesource/mscorlib/system/number.cs:728    @ system.double.parse (system.string s, system.globalization.numberstyles style, system.globalization.numberformatinfo info) [0x00000] in /library/frameworks/xamarin.ios.framework/versions/10.10.0.36/src/mono/mcs/class/referencesource/mscorlib/system/double.cs:262    @ s ystem.double.parse (system.string s, system.iformatprovider provider) [0x00000] in /library/frameworks/xamarin.ios.framework/versions/10.10.0.36/src/mono/mcs/class/referencesource/mscorlib/system/double.cs:245    @ xamarin.forms.xaml.typeconversionextensions.convertto (system.object value, system.type totype, system.func`1[tresult] getconverter, system.iserviceprovider serviceprovider) [0x001f5] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\typeconversionextensions.cs:152    @ xamarin.forms.xaml.typeconversionextensions.convertto (system.object value, system.type totype, system.func`1[tresult] minforetriever, system.iserviceprovider serviceprovider) [0x00021] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\typeconversionextensions.cs:74    @ xamarin.forms.xaml.valueconverterprovider.convert (system.object value, system.type totype, system.func`1[tresult] minforetriever, system.iserviceprovider serviceprovider) [0x00000] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\valu econverterprovider.cs:15    @ xamarin.forms.setter.xamarin.forms.xaml.ivalueprovider.providevalue (system.iserviceprovider serviceprovider) [0x00062] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.core\setter.cs:34    @ xamarin.forms.xaml.applypropertiesvisitor.visit (xamarin.forms.xaml.elementnode node, xamarin.forms.xaml.inode parentnode) [0x0004d] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\applypropertiesvisitor.cs:96    @ xamarin.forms.xaml.elementnode.accept (xamarin.forms.xaml.ixamlnodevisitor visitor, xamarin.forms.xaml.inode parentnode) [0x000b1] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\xamlnode.cs:175    @ xamarin.forms.xaml.elementnode.accept (xamarin.forms.xaml.ixamlnodevisitor visitor, xamarin.forms.xaml.inode parentnode) [0x00089] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\xamlnode.cs:172    @ xamarin.forms.xaml.fillresourcedictionariesvisitor.visit (xamarin.forms.xaml.elementnode node, xamarin.forms.xaml.inode parentnode) [0x0017e] in  c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\fillresourcedictionariesvisitor.cs:97    @ xamarin.forms.xaml.elementnode.accept (xamarin.forms.xaml.ixamlnodevisitor visitor, xamarin.forms.xaml.inode parentnode) [0x00008] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\xamlnode.cs:165    @ xamarin.forms.xaml.elementnode.accept (xamarin.forms.xaml.ixamlnodevisitor visitor, xamarin.forms.xaml.inode parentnode) [0x00089] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\xamlnode.cs:172    @ xamarin.forms.xaml.rootnode.accept (xamarin.forms.xaml.ixamlnodevisitor visitor, xamarin.forms.xaml.inode parentnode) [0x00054] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\xamlnode.cs:223    @ xamarin.forms.xaml.xamlloader.visit (xamarin.forms.xaml.rootnode rootnode, xamarin.forms.xaml.hydratationcontext visitorcontext) [0x0006d] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\xamlloader.cs:124    @ xamarin.forms.xaml.xamlloader.load (system.object view, system.strin g xaml) [0x00046] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\xamlloader.cs:76    @ xamarin.forms.xaml.xamlloader.load (system.object view, system.type callingtype) [0x0002f] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\xamlloader.cs:56    @ xamarin.forms.xaml.extensions.loadfromxaml[txaml] (txaml view, system.type callingtype) [0x00000] in c:\buildagent3\work\ca3766cfc22354a1\xamarin.forms.xaml\viewextensions.cs:36    @ someproject.app.initializecomponent () [0x00001] in c:\users\some-user\project\obj\debug\someproject.app.xaml.g.cs:19    @ someproject.app..ctor () [0x00019] in c:\users\some-user\project\app.xaml.cs:68    @ someproject.ios.appdelegate.finishedlaunching (uikit.uiapplication app, foundation.nsdictionary options) [0x000bc] in c:\users\some-userproject.ios\appdelegate.cs:38    @ (wrapper managed-to-native) uikit.uiapplication:ui applicationmain (int,string[],intptr,intptr)   @ uikit.uiapplication.main (system.string[] args, system.intptr principal, system.intptr delegate) [0x00005] in /users/builder/data/lanes/4691/d2270eec/source/xamarin-macios/src/uikit/uiapplication.cs:79    @ uikit.uiapplication.main (system.string[] args, system.string principalclassname, system.string delegateclassname) [0x00038] in /users/builder/data/lanes/4691/d2270eec/source/xamarin-macios/src/uikit/uiapplication.cs:63    @ someproject.ios.application.main (system.string[] args) [0x00001] in c:\users\some-userproject.ios\main.cs:17 

try 2:

public static readonly bindableproperty fontsizeproperty =         bindableproperty.create("fontsize",                                  typeof(double),                                  typeof(multilinebutton),                                  device.getnamedsize(namedsize.medium, typeof(label))); 

exception:

unhandled exception: system.formatexception: input string not in correct format. 

try 3:

public static readonly bindableproperty fontsizeproperty =         bindableproperty.create("fontsize",                                  typeof(double),                                  typeof(multilinebutton),                                  null); 

exception:

unhandled exception: system.typeinitializationexception: type initializer 'someproject.views.multilinebutton' threw exception. ---> system.argumentexception: not valid default value parameter name: defaultvalue 

what should use default value fontsizeproperty?

i think missing default number font size example 12d. you'll need explicitly add d number or may think int @ runtime instead of double.

public static readonly bindableproperty fontsizeproperty = bindableproperty.create(nameof(fontsize), typeof(double), typeof(multilinebutton), 12d);  [typeconverter(typeof(fontsizeconverter))] public double fontsize {     { return (double)getvalue(fontsizeproperty); }     set { setvalue(fontsizeproperty, value); } } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -