How can I set a StackPanels margins individually?

c#, code-behind, margin, stackpanel, wpf

Solution

You can also try this:

sp2.Margin = new System.Windows.Thickness{ Left = 5 };

Problem

I can set the margin of a stackpanel in code-behind like this: ``` StackPanel sp2 = new StackPanel(); sp2.Margin = new System.Windows.Thickness(5); ``` But how can I set each individually, both of these don't work: PSEUDO-CODE: ``` sp2.Margin = new System.Windows.Thickness("5 0 0 0"); sp2.Margin.Left = new System.Windows.Thickness(5); ```

Original source

Related problems