2011-06-28 5 views
0

私はこのコントロールHereを使用して、リストにバインドしてそれに応じて行を生成することができますが、それは本当にうまくいっていますが、テーブルは印刷時に表示されません。 XPSやPDFファイルは、FlowDocumentに表示されますが、空白として印刷されます。バックグラウンドとフォアグラウンドの色を、何の提案もなしに変更しようとしましたか?WYSIWYGただし、印刷しない場合

+0

あなたも埋没費用に捕捉されない場合、私はそれとして、CSSへの切り替えを、検討します印刷テンプレートを許可します。 –

+0

@Gregory:WPFの 'FlowDocument'でCSSを使うとどうなるか分かりません。 – user7116

+0

どちらかというと、問題の横には本当に混乱しています。どうすればプリンタが私のテーブルを見ることができないのですか?コントロールの中にあり、問題のない他のコントロールを見ることができます – Musaab

答えて

0

私はちょうどその例(Create Flexible UIs With Flow Documents And Data Binding)を実装して、あなたと同じ問題を経験しました。

BindableRunDataContextが正しく設定されていないという問題がありました。 (FixupDataContextヘルパーメソッドを使用して)コンテキストを修正する必要がある記事で説明したように、FrameworkContentElementにはDataContextを設定し、以前は固定されたコンテキストをクリアします(UnFixupDataContextヘルパーメソッドを使用)。 これらの命令の実行順序は重要ですです。記事をもう一度読んで理解していることを確認してください。私はそれを何度か読み直し、彼が何を話しているかを本当に理解するためのコードを研究しなければなりませんでした。

私は実装を一歩前進させ、TableCellの他の要素をバインドするデータのサポートを追加しました。この変更には、添付プロパティを使用してDataContextが 'fixed'の要素を識別してから、FrameworkContentElementsに加えてFrameworkElementsに対しても機能するようにヘルパーメソッドを展開します。

HTH、

編集:

public static class DataContextHelper 
{ 

    #region UseAncestorDataContext 

    public static readonly DependencyProperty UseAncestorDataContextProperty = DependencyProperty.RegisterAttached("UseAncestorDataContext", typeof(bool), typeof(DataContextHelper), 
                        new FrameworkPropertyMetadata(false, DataContextHelper.OnUseAncestorDataContextChanged)); 

    public static bool GetUseAncestorDataContext(DependencyObject d) 
    { 
     return (bool)d.GetValue(UseAncestorDataContextProperty); 
    } 

    public static void SetUseAncestorDataContext(DependencyObject d, bool value) 
    { 
     d.SetValue(UseAncestorDataContextProperty, value); 
    } 

    private static void OnUseAncestorDataContextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
    { 
     if ((bool)e.NewValue) 
      UseAncestorDataContext(d); 
    } 

    #endregion 

    /// <summary> 
    /// If you use a Bindable flow document element more than once, you may encounter a "Collection was modified" 
    /// exception. The error occurs when the binding is updated because of a change to an inherited dependency 
    /// property. The most common scenario is when the inherited DataContext changes. It appears that an inherited 
    /// properly like DataContext is propagated to its descendants. When the enumeration of descendants gets to 
    /// a Bindable, the dependency properties of that element change according to the new DataContext, which change 
    /// the (non-dependency) properties. However, for some reason, changing the flow content invalidates the enumeration 
    /// and raises an exception. 
    /// </summary>   
    public static void UseAncestorDataContext(DependencyObject element) 
    {    
     if (element is FrameworkContentElement) 
     { 
      FrameworkContentElement contentElement = (FrameworkContentElement)element; 
      Binding binding = new Binding(FrameworkContentElement.DataContextProperty.Name); 
      binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(FrameworkElement), 1); 
      contentElement.SetBinding(FrameworkContentElement.DataContextProperty, binding); 
     } 
     else if (element is FrameworkElement) 
     { 
      FrameworkElement frameworkElement = (FrameworkElement)element; 
      Binding binding = new Binding(FrameworkElement.DataContextProperty.Name); 
      binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(FrameworkElement), 1); 
      frameworkElement.SetBinding(FrameworkContentElement.DataContextProperty, binding); 
     } 
    } 

    public static void ClearDataContextBinding(DependencyObject d) 
    { 
     while (RestoreDataContextRecursive(d));    
    } 

    private static bool RestoreDataContextRecursive(DependencyObject d) 
    {    
     if (d is FrameworkContentElement && GetUseAncestorDataContext(d)) 
     { 
      Binding binding = BindingOperations.GetBinding(d, FrameworkContentElement.DataContextProperty); 
      if (binding != null && binding.Path != null && binding.Path.Path == FrameworkContentElement.DataContextProperty.Name 
       && binding.RelativeSource != null && binding.RelativeSource.Mode == RelativeSourceMode.FindAncestor && binding.RelativeSource.AncestorType == typeof(FrameworkElement) && binding.RelativeSource.AncestorLevel == 1) 
      { 
       BindingOperations.ClearBinding(d, FrameworkContentElement.DataContextProperty); 
       return true; 
      } 
     } 
     else if (d is FrameworkElement && GetUseAncestorDataContext(d)) 
     { 
      Binding binding = BindingOperations.GetBinding(d, FrameworkElement.DataContextProperty); 
      if (binding != null && binding.Path != null && binding.Path.Path == FrameworkElement.DataContextProperty.Name 
       && binding.RelativeSource != null && binding.RelativeSource.Mode == RelativeSourceMode.FindAncestor && binding.RelativeSource.AncestorType == typeof(FrameworkElement) && binding.RelativeSource.AncestorLevel == 1) 
      { 
       BindingOperations.ClearBinding(d, FrameworkElement.DataContextProperty); 
       return true; 
      } 
     } 

     // As soon as we have disconnected a binding, return. Don't continue the enumeration, since the collection may have changed 
     foreach (object child in LogicalTreeHelper.GetChildren(d)) 
     { 
      if (child is DependencyObject && RestoreDataContextRecursive((DependencyObject)child)) 
       return true; 
     } 

     return false; 
    } 

} 

使用

<DataTemplate x:Key="PercentCellTemplate"> 
     <documents:ContentFragment> 
      <TableCell Style="{StaticResource TableCellStyle}" BorderThickness="0,0,1,0"> 
       <Paragraph> 
        <Rectangle Width="14" Height="14" VerticalAlignment="Center" Margin="0,6,0,0" Fill="{Binding Path=Result, Mode=OneWay, Converter={StaticResource MappingConverterResultEnumToIconResource}}" 
           documents:DataContextHelper.UseAncestorDataContext="True"/> 
        <documents:DocumentRun Style="{StaticResource ReportDocument_NormalRunStyle}" Text="{Binding Path=Percent, Mode=OneWay, StringFormat={}{0:0.000}%}" 
              BaselineAlignment="Center" documents:DataContextHelper.UseAncestorDataContext="True" /> 
       </Paragraph> 
      </TableCell> 
     </documents:ContentFragment> 
    </DataTemplate> 
+0

これに感謝しています。なぜ私はそれを解決しなかったので、私は問題を解決したし、確かにデータインターフェイスだったので、私は彼らが次の.NETリリースでこれを考慮する必要があると思う。 – Musaab

+0

あなたは大歓迎です。フロードキュメントを生成/印刷するためのソリューションは明らかに欠けているので、自分で1週間かけて返済することができれば、より大きな利益を得ることができます。私はちょうど 'FrameworkElements'のバインディングを修正するヘルパーメソッドの私のバージョンを含める答えを編集しました。 – Dennis

関連する問題