Add GridPattern from behind code

Hi , how can I add from behind code following:

                            <go:Diagram.GridPattern  >
                                <go:GridPattern CellSize="10 10"  >
                                    <Path Stroke="WhiteSmoke"  StrokeThickness="1" go:GridPattern.Figure="HorizontalLine"  />
                                    <Path Stroke="WhiteSmoke"  StrokeThickness="1" go:GridPattern.Figure="VerticalLine"  />
                                </go:GridPattern>
                            </go:Diagram.GridPattern>

Something like

    GridPattern myPhysicalDiagramGridPattern = new GridPattern()
    {
        CellSize = new System.Windows.Size(10, 10),
    };

Can I add PATH properties from code or set that as style from APP XAML? Thanks…

I haven’t even tried compiling this, but it ought to be equivalent to your XAML:

var grid = new GridPattern() {
    CellSize = new Size(10, 10)
};

var path = new Path() {
    Stroke = new SolidColorBrush(Colors.WhiteSmoke),
    StrokeThickness = 1
};
GridPattern.SetFigure(path, GridFigure.HorizontalLine);
grid.Children.add(path);

path = new Path() {
    Stroke = new SolidColorBrush(Colors.WhiteSmoke),
    StrokeThickness = 1
};
GridPattern.SetFigure(path, GridFigure.VerticalLine);
grid.Children.add(path);

myDiagram.GridPattern = grid;

Thanks a lot , that works , final example separated both PATH variables…

var grid = new GridPattern() {CellSize = new Size(10, 10)};
var pathhor = new Path() { Stroke = new SolidColorBrush(Colors.WhiteSmoke),StrokeThickness = 1};
GridPattern.SetFigure(pathhor , GridFigure.HorizontalLine);
grid.Children.Add(pathhor);
var pathver = new Path() {Stroke = new SolidColorBrush(Colors.WhiteSmoke),StrokeThickness = 1};
GridPattern.SetFigure(pathver , GridFigure.VerticalLine);
grid.Children.Add(pathver);
myDiagram.GridPattern = grid;