2009-11-04 17 views
8

Creé esta imagen en MS Word y trato de replicar el estilo en mi aplicación WPF utilizando los documentos. En primer lugar el 'de':Documento de WPF: Obtención de los bordes de la celda de la tabla derecha

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

siguiente mi intento de replicar:

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

Mi pregunta es probablemente bastante obvio. ¿Qué estoy haciendo mal? No puedo encontrar una propiedad de relleno en el grupo de filas o la fila. A continuación se muestra el código:

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; 
    } 

Respuesta

9

Por desgracia no se puede establecer la frontera para un TableRow en un FlowDocument. Solo está disponible para Table o TableCell. Incluso me pregunto por qué esto no fue provisto.

Aunque una forma de lograr un efecto fila frontera es utilizar frontera de todas las células en conjunción con BorderThickness, y el establecimiento de CellSpacing del recipiente Table a 0. Por ejemplo:

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, lo siento por este respuesta tardía, pero acabo de llegar a esta pregunta. Tal vez la respuesta puede ayudar a otros.

En este caso particular, debe establecer una tabla. Grosor de trama en 1, tabla.Espacio de celda en 0, y el borde superior O inferior para cada celda.

Para evitar ajustar el grosor a (0,1,0,0) para cada celda, puede usar estilos. Hay muchas formas de hacerlo, pero te mostraré una simple. En su App.xaml, escribir lo siguiente:

<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> 

Después de eso, combinar el diccionario de aplicación en su documento o una mesa, con algo como:

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

Usted puede tener estilos para todo el documento, una tabla individual e incluso una fila o celda individual.

+0

si las celdas no son de la misma altura, entonces tiene problemas – GorillaApe

Cuestiones relacionadas