You can walk the control tree and, if the current control is of type Grid, add your border to it.
Here's some pseudocode that looks shockingly like C# and may actually compile and work:
private void AddGrid(Control c){
foreach(var child in c.Children)
AddGrid(child);
if(this is Grid)
this.Border = new Border(/* whatever */);
}
Alternatively, in the Resources of the control that contains your dynamic xaml, you can add a Style that alters the appearance of all Grids and adds the border you want around it. This is a good resource for learning how to do this. Just keep in mind that if you add the style to the window's resources or the application's resources it will affect all controls in your window or application, respectively. Adding it to the immediate parent of the dynamic xaml will (? never tried this before) affect only its child control's templates.