Hello There ! How to set Margin for Border

Created at 08 Apr 2021, 14:56
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!
IM

imrealfighter

Joined 09.11.2020

Hello There ! How to set Margin for Border
08 Apr 2021, 14:56


Hello There Again Everyone

I'm having an issue with on how to set Margin for Border up.

normally when we setting up a border we code like this (This is a border for a button)

 

 var borderForButton = new Border 
            {
                VerticalAlignment = PanelVerticalAlignment,
                HorizontalAlignment = PanelHorizontalAlignment,
                Margin = "10 20 30 40",
                Width = 100,
                Height = 30,
                Child = button
            };

 

ok It seems  pretty easy to do. but is there a way that we could set on each margin side by our value on variable ?
I want to set a margin like this

int marginLeft = 10;

int marginTop = 20;

int marginRight =30;

int marginBottom = 40;

 

 var borderForButton = new Border 
            {
                VerticalAlignment = PanelVerticalAlignment,
                HorizontalAlignment = PanelHorizontalAlignment,
                Margin = "marginLeft marginTop marginRight marginBotttom",
                Width = 100,
                Height = 30,
                Child = button
            };

if we set it like this it will show an error.

so could someone suggest me the right way to do it ?

Thank you.

 


 


@imrealfighter
Replies

amusleh
08 Apr 2021, 15:44

Hi,

This sample might help you:

using cAlgo.API;

namespace cAlgo
{
    /// <summary>
    /// This sample shows how to use Thickness for defining a chart control margin
    /// </summary>
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ThicknessSample : Indicator
    {
        protected override void Initialize()
        {
            var stackPanel = new StackPanel
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                BackgroundColor = Color.Gold,
                Opacity = 0.6
            };

            var rectangle = new Rectangle
            {
                StrokeColor = Color.Blue,
                FillColor = Color.Red,
                StrokeThickness = 2,
                Margin = new Thickness(10, 5, 10, 5),
                Width = 300,
                Height = 100,
            };

            stackPanel.AddChild(rectangle);

            Chart.AddControl(stackPanel);
        }

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

MArgin property type is Thickness.


@amusleh

imrealfighter
09 Apr 2021, 16:07

RE:

amusleh said:

Hi,

This sample might help you:

using cAlgo.API;

namespace cAlgo
{
    /// <summary>
    /// This sample shows how to use Thickness for defining a chart control margin
    /// </summary>
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ThicknessSample : Indicator
    {
        protected override void Initialize()
        {
            var stackPanel = new StackPanel
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                BackgroundColor = Color.Gold,
                Opacity = 0.6
            };

            var rectangle = new Rectangle
            {
                StrokeColor = Color.Blue,
                FillColor = Color.Red,
                StrokeThickness = 2,
                Margin = new Thickness(10, 5, 10, 5),
                Width = 300,
                Height = 100,
            };

            stackPanel.AddChild(rectangle);

            Chart.AddControl(stackPanel);
        }

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

MArgin property type is Thickness.

Hi There ! amusleh
First of all Nice to meet you and thank you for your kind and help.

I know that margin property type is thickness but I don't know how to initialize it.
all I know is from an example that come up with ctrader program.

I try it and it works !.

Thank you Amusleh .

P.s. also I try this and it works too.

Margin = string.Format("{0} {1} 20 10", marginLeft, marginTop),

 


@imrealfighter