Печать сетки WPF без GridLines - PullRequest
       9

Печать сетки WPF без GridLines

2 голосов
/ 27 октября 2011

У меня есть сетка, и я хочу напечатать всю сетку grid.each в своем текстовом поле сетка установлена ​​на ShowGridLines = false;, а также у меня есть метод удаления границы текстового поля.

private void DeletBorder()
{
    Thickness bor = new Thickness(0.0);
    for (int i = 0; i < this.gridArray.Length; i++)
    {
        foreach (Control ctrl in this.gridArray[i].Children)
        {
            if (ctrl.GetType() == typeof(TextBox))
            {
                ((TextBox) ctrl).BorderThickness = bor;
            }
        }
    }
}

Я пытаюсь распечатать все сетки в массиве этим методом:

private void button1_Click(object sender, RoutedEventArgs e)
{
    if (this.comboBox1.SelectedIndex > -1)
    {
        PrintDialog printDlg = new PrintDialog();
        this.DeletBorder();
        if (printDlg.ShowDialog() == true)
        {
            this.DeletBorder();
            foreach (Grid item in this.gridArray)
            {
                printDlg.PrintVisual(item, "Stiker Print Job");
            }
        }
    }
    else
    {
        MessageBox.Show("you must select the page layout first");
    }
}

но в результате получается, что только первая страница печатается без border / gridLines, а другая все еще печатается с border / gridLines

1 Ответ

1 голос
/ 26 декабря 2014

Первая проблема в том, что дважды звонить this.DeleteBorder() бессмысленно.

Во-вторых, предполагая, что gridArray имеет только Grid с; вам не нужно показывать линии сетки для каждого Grid. Попробуйте это:

if (printDlg.ShowDialog() == true)
{
    /* remove this--this.DeletBorder(); */

    int index = 0;
    foreach(Grid item in this.gridArray)
    {
        item.ShowGridLines = false;
        // Add an identifier so you know what job is printing. You may need to call:
        // item.UpdateLayout();
        printDlg.PrintVisual(item, "Stiker Print Job: " + index.ToString());
    }
}

Если это не решит вашу проблему, предоставьте пример кода XAML и / или более, чтобы воссоздать проблему на http://gist.github.com.

...