tkawa
Topic Author
Posts: 16
Joined: 07 Nov 2018, 05:34

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

26 Sep 2019, 14:13

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;
}

Tags:
 
User avatar
sfernandez
Site Admin
Posts: 1911
Joined: 22 Dec 2011, 19:20

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

27 Sep 2019, 17:55

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;
};
 
 
User avatar
sfernandez
Site Admin
Posts: 1911
Joined: 22 Dec 2011, 19:20

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

04 Oct 2019, 17:03

Thanks for the report.

Who is online

Users browsing this forum: No registered users and 1 guest