2014-01-09 92 views
1

我是Silverlight的新手。打印時,我需要刪除DatePicker圖標。所以我編寫了這個代碼來在打印時刪除圖標。如果點擊打印對話框中的打印按鈕,它正常工作。但如果我關閉打印對話框日期選取器圖標不會出現。我必須在打印對話框關閉的情況下編寫代碼。我無法找到打印對話框的事件。如何處理Silverlight中的打印對話框關閉事件5

這是打印的代碼:

private StackPanel Downloaded_Data(StackPanel Sp_Element) 
    { 
     foreach (UIElement ele in Sp_Element.Children) 
     { 
      if (ele is FirstPageTC) 
      { 
       if ((ele as FirstPageTC).Content is StackPanel) 
        Downloaded_Data((ele as FirstPageTC).Content as StackPanel); 
       if ((ele as FirstPageTC).Content is Grid) 
        Download_Grid((ele as FirstPageTC).Content as Grid); 
      } 
      if (ele is Blank_Page) 
      { 
       if ((ele as Blank_Page).Content1 is StackPanel) 
        Downloaded_Data((ele as Blank_Page).Content1 as StackPanel); 
       if ((ele as Blank_Page).Content1 is Grid) 
        Download_Grid((ele as Blank_Page).Content1 as Grid); 
      } 


      if (ele is DatePicker) 
      { 
       DatePicker s = ele as DatePicker; 
       s.Style = App.Current.Resources["DateStyle"] as Style; 
       // s.Background = new SolidColorBrush(Color.FromArgb(255, 143, 188, 143)); 
      } 

      if (ele is StackPanel) 
      { 
       Downloaded_Data(ele as StackPanel); 
      } 
      if (ele is Grid) 
      { 
       Download_Grid(ele as Grid); 
      } 
     } 
     return Sp_Element; 
    } 

    public void Download_Grid(Grid grid_down) 
    { 
     foreach (UIElement ele in grid_down.Children) 
     { 
      if (ele is Border) 
      { 
       UIElement ele_b = (ele as Border).Child; 
       if (ele_b is DatePicker) 
       { 
        DatePicker s = ele_b as DatePicker; 

        s.Style = App.Current.Resources["DateStyle"] as Style; 
        // s.Background = new SolidColorBrush(Color.FromArgb(255, 143, 188, 143)); 
       } 

       //here 
       if (ele_b is Grid) 
       { 
        Download_Grid(ele_b as Grid); 
       } 
       if (ele_b is StackPanel) 
       { 
        Downloaded_Data(ele_b as StackPanel); 
       } 
      } 
     } 
    } 

    private void Downloaded_Datepicker(StackPanel Sp_Element) 
    { 
     foreach (UIElement ele in Sp_Element.Children) 
     { 
      if (ele is FirstPageTC) 
      { 
       if ((ele as FirstPageTC).Content is StackPanel) 
        Downloaded_Datepicker((ele as FirstPageTC).Content as StackPanel); 
       if ((ele as FirstPageTC).Content is Grid) 
        Download_GridDate((ele as FirstPageTC).Content as Grid); 
      } 
      if (ele is Blank_Page) 
      { 
       if ((ele as Blank_Page).Content1 is StackPanel) 
        Downloaded_Datepicker((ele as Blank_Page).Content1 as StackPanel); 
       if ((ele as Blank_Page).Content1 is Grid) 
        Download_GridDate((ele as Blank_Page).Content1 as Grid); 
      } 


      if (ele is DatePicker) 
      { 
       DatePicker s = ele as DatePicker; 

       s.Style = App.Current.Resources["DateNormal"] as Style; 
      } 

      if (ele is StackPanel) 
      { 
       Downloaded_Datepicker(ele as StackPanel); 
      } 
      if (ele is Grid) 
      { 
       Download_GridDate(ele as Grid); 
      } 
     } 

    } 

    public void Download_GridDate(Grid grid_down) 
    { 
     foreach (UIElement ele in grid_down.Children) 
     { 
      if (ele is Border) 
      { 
       UIElement ele_b = (ele as Border).Child; 
       if (ele_b is DatePicker) 
       { 
        DatePicker s = ele_b as DatePicker; 
        s.Style = App.Current.Resources["DateNormal"] as Style; 

       } 

       //here 
       if (ele_b is Grid) 
       { 
        Download_GridDate(ele_b as Grid); 
       } 
       if (ele_b is StackPanel) 
       { 
        Downloaded_Datepicker(ele_b as StackPanel); 
       } 
      } 
     } 
    } 

    public void PrintPage(StackPanel sp_Print) 
    { 
     foreach (UIElement sp_Element in sp_Print.Children) 
     { 
      if (sp_Element is StackPanel) 
      { 
       StackPanel printableSpnel=Downloaded_Data(sp_Element as StackPanel); 
       //sp_Printing[count] = sp_Element as StackPanel; 
       //count = count + 1;  
       sp_Printing[count] = printableSpnel; 
       count = count + 1; 
      } 
     } 
     WithDatePickerIcon = sp_Print as StackPanel; 
     print_Doc.PrintPage += new EventHandler<PrintPageEventArgs>(print_Doc_PrintPage); 
     print_Doc.Print("REOSK Printing"); 
    } 

    void print_Doc_PrintPage(object sender, PrintPageEventArgs e) 
    { 

     if (count == i) 
     {     
      e.PageVisual = sp_Printing[i]; 
      e.HasMorePages = false; 
      Downloaded_Datepicker(WithDatePickerIcon as StackPanel); 
     }    
     else 
     {  
      e.PageVisual = sp_Printing[i];     
      e.HasMorePages = true; 
      i = i + 1; 
      Downloaded_Datepicker(WithDatePickerIcon as StackPanel); 
     } 
    } 

回答

0

我不能說我完全理解你的代碼,但是有一個關鍵的東西錯了,這可能是你的問題:

你不應該在假設打印開始時(甚至不禁用打印按鈕或指示任何內容),不會開始修改程序的任何狀態,除非在PrintDocument上調用BeginPrint事件。在EndPrint事件中,您所做的所有事情都會恢復正常。

因此,大部分PrintPage方法(不應該稱爲PrintPage*s*?)應該可能存在於偵聽BeginPrint事件的處理程序中。

打印API的工作客戶端需要收聽所有這三個事件。打印以BeginPrint開頭,而不是打電話給Print:用戶可以按照您的經驗單擊取消來解除打印。