I’m developing a WPF application, and I have created a custom usercontrol because I need to create instances of it, on the main window. So, this is how I create a new instance:
var MyCard = new vCard();
MainGrid.Children.Add(MyCard);
Grid.SetColumn(MyCard, 1);
Grid.SetRow(MyCard, 0);
But I need to place every one in order, so, how can I set the X & Y position of each one. I’ve tried creating a method in my usercontrol to set the margin property, example:
public void SetX(double X)
{
double Y =this.Margin.Top;
this.Margin = new Thickness(X, Y, 0, 0);
}
But, it’s not working. Is there another way to do it?
An often neglected control is the UniformGrid.
Proceed to add the
UserControlas you were before.This will provide a nice and evenly distributed container for your items. If you want to adjust the spacing between items there are couple ways to do it, with the easiest being the adjustment of the
Marginproperty on yourUserControlitself.