When I have the following setup, the last column having a width of * causes the datagrid to create huge horizontal scrollbars (extends grid to several widths of the screen).
If you remove
dg.Columns[2].Width = new DataGridLength(1, DataGridLengthUnitType.Star);
the problem should go away. Can I ask why you want the last column to take the rest of the space? The column actually knows to resize itself properly to fit its cell size and column header size.
Also, if you don't specify the column's width, then you don't really need a scrollviewer to scroll and see all the columns. The datagrid has a scrollviewer built in and when there are columns out of the screen the horizontal scrollbar will apear.
I hope this helps. :)
you need to put a maxwidth on the scrollviewer? otherwise width is defaulted to auto and maxwidth is infinity