2009-11-04 9 views
8

Ich habe dieses Bild in MS Word erstellt und ich versuche, den Stil in meiner WPF-App mit den Dokumenten zu replizieren. Zunächst wird das 'von':WPF-Dokument: Abrufen der Tabellenzellenrahmen richtig

alt text http://img337.imageshack.us/img337/1275/correntborder.png

Next mein Versuch zu replizieren:

alt text http://img156.imageshack.us/img156/1711/extrawhiteborder.png

Meine Frage wahrscheinlich ziemlich offensichtlich ist. Was mache ich falsch? Ich kann keine Padding-Eigenschaft für die Zeilengruppe oder die Zeile finden. Unten ist mein Code:

public override FlowDocument CreateDocumentSection(IInteractivityElement pElement) 
    { 
     var result = new FlowDocument(); 

     // show the header 
     result.Blocks.Add(CreateHeading(pElement.Header)); 

     // we don't show anything else if there aren't any columns 
     var nrColumns = pElement.GetIntegralData("CurrentColumnCount") ?? 0; 
     if (nrColumns == 0) return result; 

     Table mainTable = new Table(); 
     result.Blocks.Add(mainTable); 

     // columns 
     for (long tableIdx = 0; tableIdx < nrColumns; tableIdx++) 
     { 
      var newColumn = new TableColumn(); 
      mainTable.Columns.Add(newColumn); 
     } 

     // row group for header 
     TableRowGroup rowGroup = new TableRowGroup(); 
     mainTable.RowGroups.Add(rowGroup); 

     // row for header 
     TableRow headerRow = new TableRow(); 
     headerRow.Background = new SolidColorBrush(Color.FromRgb(79, 129, 189)); 
     headerRow.Foreground = new SolidColorBrush(Colors.White); 
     rowGroup.Rows.Add(headerRow); 

     // add columns for each header cell 
     for (long tableIdx = 0; tableIdx < nrColumns; tableIdx++) 
     { 
      var headerNameKey = CreateColumnNameKey(tableIdx); 
      TableCell headerCell = new TableCell(new Paragraph(new Run(pElement.GetStringData(headerNameKey)))); 
      headerRow.Cells.Add(headerCell); 
     } 

     TableRow emptyRow = new TableRow(); 
     emptyRow.Foreground = new SolidColorBrush(Colors.Gray); 
     rowGroup.Rows.Add(emptyRow); 

     TableCell emptyInstructionCell = new TableCell(); 
     emptyInstructionCell.BorderBrush = new SolidColorBrush(Color.FromRgb(79, 129, 189)); 
     emptyInstructionCell.BorderThickness = new Thickness(1.0); 
     emptyInstructionCell.ColumnSpan = Convert.ToInt32(nrColumns); 
     emptyInstructionCell.Blocks.Add(new Paragraph(new Run(pElement.Instruction))); 
     emptyRow.Cells.Add(emptyInstructionCell); 

     return result; 
    } 

Antwort

9

Leider können Sie nicht die Grenze für eine TableRow in einem FlowDocument gesetzt. Es ist nur für die Table oder die TableCell verfügbar. Selbst ich frage mich, warum das nicht zur Verfügung gestellt wurde.

Obwohl eine Möglichkeit, eine Reihe Grenzeffekt zu erreichen, ist mit BorderThickness Grenze aller Zellen in Verbindung zu verwenden, und CellSpacing des Behälters Table auf 0. Für zB Einstellung:

table.CellSpacing = 0; 
... 
cellLeft.BorderThickness= new Thickness(1, 1, 0, 1); 
... 
cellCenter.BorderThickness= new Thickness(0, 1); 
... 
cellRight.BorderThickness= new Thickness(0, 1, 1, 1); 
5

Yogesh, traurig für diese späte Antwort, aber ich bin gerade zu dieser Frage gekommen. Vielleicht kann die Antwort anderen helfen.

In diesem speziellen Fall müssen Sie eine Tabelle.BorderThickness auf 1, table.CellSpacing auf 0 und den oberen ODER unteren Rand für jede Zelle festlegen.

Um zu vermeiden, die Dicke für jede Zelle auf (0,1,0,0) zu setzen, können Sie Stile verwenden. Es gibt viele Möglichkeiten, dies zu tun, aber ich werde Ihnen ein einfaches zeigen. In Ihrem App.xaml, schreiben Sie folgendes:

<Application x:Class="YourNamespace.App" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:doc="clr-namespace:System.Windows.Documents;assembly=PresentationFramework"> 

    <Application.Resources> 
     <Style TargetType="doc:TableCell" > 
      <Setter Property="BorderBrush" Value="Blue" /> 
      <Setter Property="BorderThickness" Value="0,1,0,0" /> 
      <Setter Property="FontSize" Value="12" /> 
      <Setter Property="Padding" Value="2" /> 
     </Style>   
    </Application.Resources> 
</Application> 

Danach, fusionieren die Anwendung Wörterbuch in Ihr Dokument oder Tabelle, mit so etwas wie:

mainTable.Resources.MergedDictionaries.Add(App.Current.Resources); 

Sie Stile für das gesamte Dokument haben kann, eine einzelne Tabelle und sogar eine einzelne Zeile oder Zelle.

+0

Wenn Zellen nicht auf gleicher Höhe sind, haben Sie Probleme – GorillaApe