Page 1 of 1

[c++]How to bind FontSize and specify font size as "pt", "in" and "cm"

Posted: 26 Sep 2019, 14:13
by tkawa
Hi,

I try to bind FontSize and specify "pt".
How to convert from NsString to float?
In WPF, it can convert from string to double by FontSizeConverter().

XAML
<TextBlock  FontSize="{Binding FontSize}"... />
cpp
float GetFontSize() const{
	NsString fontSizeString = "20pt";
	float fontSize;
	//Convert from NsString to float
	return fontSize;
}

Re: [c++]How to bind FontSize and specify font size as "pt", "in" and "cm"

Posted: 27 Sep 2019, 17:55
by sfernandez
This is a bug, our FontSize property doesn't have a FontSizeConverter assigned, it only accepts float values, could you please report it?

In the meantime you can create a LengthConverter and use it to obtain the font size from the string value:
class ViewModel: public BaseComponent
{
public:
  ViewModel()
  {
    mFontSizeConverter = NsCreateComponent<TypeConverter>(NsSymbol("Converter<Length>"));
  }

  void UpdateFontSize(const char* size)
  {
    Ptr<BaseComponent> result;
    if (mFontSizeConverter->TryConvertFromString(size, result))
    {
      mFontSize = Boxing::Unbox<float>(result);
    }
  }
  ...
  
private:
  Ptr<TypeConverter> mFontSizeConverter;
  float mFontSize;
};

Re: [c++]How to bind FontSize and specify font size as "pt", "in" and "cm"

Posted: 30 Sep 2019, 06:55
by tkawa

Re: [c++]How to bind FontSize and specify font size as "pt", "in" and "cm"

Posted: 04 Oct 2019, 17:03
by sfernandez
Thanks for the report.