FontFamily in Button Text?

Created at 29 Oct 2024, 12:13
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
CT

ctid5996231

Joined 26.06.2024

FontFamily in Button Text?
29 Oct 2024, 12:13


Hello,

I seem to be unable to set the FontFamily of a button control, the FontFamily property exists for the control but setting it seems to have no effect and the Button text remains in the default font. Example code below.

 

using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
	public class buttonTest : Indicator
	{

		protected override void Initialize() {
			Print("Initialise");

			var style = new Style();
			style.Set(ControlProperty.FontFamily, "Consolas");

			var button = new Button()
			{
				Text = "Test",
				Width = 100,
				Height = 30,
				IsVisible = true,
				FontFamily = "Consolas",
				FontSize = 20,
				Style = style
			};

			button.Click += OnClick;

			Chart.AddControl(button);

		}

		private void OnClick(ButtonClickEventArgs args)	{

			Print(args.Button.Style.Get(ControlProperty.FontFamily));

		}


		public override void Calculate(int index) { 
		
		}
	}
}

NB the Consolas font does exist on my system, I can use it with TextBox etc without any issues.

Many thanks,

Mat

 


@ctid5996231
Replies

ctid5996231
12 Nov 2024, 14:51

@Panagiotis?


@ctid5996231

PanagiotisCharalampous
13 Nov 2024, 10:41

RE: FontFamily in Button Text?

ctid5996231 said: 

@Panagiotis?

Hi there,

It looks like a bug. The team will investigate and resolve in an upcoming update.

Best regards,

Panagiotis


@PanagiotisCharalampous

ctid5996231
13 Nov 2024, 12:33

RE: RE: FontFamily in Button Text?

PanagiotisCharalampous said: 

ctid5996231 said: 

@Panagiotis?

Hi there,

It looks like a bug. The team will investigate and resolve in an upcoming update.

Best regards,

Panagiotis

Epic, thank you!


@ctid5996231

afhacker
14 Nov 2024, 11:39 ( Updated at: 14 Nov 2024, 11:40 )

Hi,

As a workaround you can try setting Button content to a TextBlock with your font properties instead of using Button Text property:

var button = new Button()
{
Content = new TextBlock {Text = "Test", FontFamily = "Consolas", FontSize = 20},
Width = 100,
Height = 30,
IsVisible = true,
};


@afhacker

ctid5996231
14 Nov 2024, 11:43

RE: FontFamily in Button Text?

afhacker said: 

Hi,

As a workaround you can try setting Button content to a TextBlock with your font properties instead of using Button Text property:

var button = new Button()
{
Content = new TextBlock {Text = "Test", FontFamily = "Consolas", FontSize = 20},
Width = 100,
Height = 30,
IsVisible = true,
};

Oh, wow. That is interesting, thank you!


@ctid5996231

ctid5996231
21 Nov 2024, 11:35

RE: RE: FontFamily in Button Text?

@Panagiotis

My platform has just updated itself to 5.0.46, and the  Button font issue appears to have been fixed, thanks…

However, something  else is now broken, all buttons' ForegroundColor is now white, and I'm unable to change it…?

Thanks,

Mat

 


@ctid5996231

PanagiotisCharalampous
21 Nov 2024, 13:35

RE: RE: RE: FontFamily in Button Text?

ctid5996231 said: 

@Panagiotis

My platform has just updated itself to 5.0.46, and the  Button font issue appears to have been fixed, thanks…

However, something  else is now broken, all buttons' ForegroundColor is now white, and I'm unable to change it…?

Thanks,

Mat

 

Hi Mat,

We will fix this as well.

Best regards,

Panagiotis


@PanagiotisCharalampous