resize width datagridtextcolumn

resize - WPF DataGridColumnWidth no funciona bien cuando PrintVisual



datagridtextcolumn (0)

Tengo un ucReceipt.xml que se ve bien en el modo de diseño o incluso se ve bien al abrir la ventana http://prntscr.com/5xl11h :

<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Receipt.ReceiptItems}" IsReadOnly="True" CanUserSortColumns="False" CanUserResizeColumns="False" RowHeaderWidth="0" Grid.Row="4"> <DataGrid.Columns> <DataGridTextColumn Binding="{Binding ItemNo}" Header="No" Width="0.5*" /> <DataGridTextColumn Binding="{Binding cloth.Name}" Header="Description" Width="*" /> <DataGridTextColumn Binding="{Binding Quantity}" Header="Qty" Width="auto"> <DataGridTextColumn.CellStyle> <Style> <Setter Property="TextBlock.HorizontalAlignment" Value="Stretch" /> <Setter Property="TextBlock.TextAlignment" Value="Right" /> </Style> </DataGridTextColumn.CellStyle> </DataGridTextColumn> <DataGridTextColumn Binding="{Binding UnitPrice}" Header="Price" Width="auto"> <DataGridTextColumn.CellStyle> <Style> <Setter Property="TextBlock.HorizontalAlignment" Value="Stretch" /> <Setter Property="TextBlock.TextAlignment" Value="Right" /> </Style> </DataGridTextColumn.CellStyle> </DataGridTextColumn> <DataGridTextColumn Binding="{Binding SubTotal}" Header="Amount" Width="auto"> <DataGridTextColumn.CellStyle> <Style> <Setter Property="TextBlock.HorizontalAlignment" Value="Stretch" /> <Setter Property="TextBlock.TextAlignment" Value="Right" /> </Style> </DataGridTextColumn.CellStyle> </DataGridTextColumn> </DataGrid.Columns> </DataGrid>

Sin embargo, cuando intento PrintVisual con los siguientes códigos, DataGridColumns no cambia el tamaño correctamente http://prntscr.com/5xl1ds

if (SelectReceiptWindow.SelectedReceipt != null) { Receipt = SelectReceiptWindow.SelectedReceipt; if (ReceiptWindow == null) ReceiptWindow = new ReceiptViewModel(); ReceiptWindow.Receipt = Receipt; ReceiptWindow.IsOpen = true; // FIXME!!! remove after implementing CloseCmd if (ReceiptWindow.IsOpen) ReceiptWindow.IsOpen = false; switch(ReceiptWindow.ReceiptActions) { case 1: // print Receipt System.Windows.Controls.PrintDialog dlg = new System.Windows.Controls.PrintDialog(); ucReceipt r = new ucReceipt(); r.Width = 300; r.Height = 600; r.DataContext = ReceiptWindow; dlg.ShowDialog(); dlg.PrintVisual((System.Windows.Media.Visual)r, "Receipt"); break; } }

¿Alguna idea?