2009-11-04 19 views
8

Utworzono to zdjęcie w MS Word i próbuję replikować styl w mojej aplikacji WPF przy użyciu Dokumentów. Najpierw 'z':Dokument WPF: Uzyskiwanie granic tabeli Tabela prawa

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

Następny moja próba replikacji:

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

Moje pytanie jest chyba dość oczywiste. Co ja robię źle? Nie mogę znaleźć właściwości wypełniania dla grup wierszy lub wiersza. Poniżej jest mój kod:

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

Odpowiedz

9

Niestety nie można ustawić granicę za TableRow w FlowDocument. Jest dostępny tylko dla Table lub TableCell. Nawet zastanawiam się, dlaczego tak się nie stało.

Chociaż jeden sposób uzyskania efektu rząd graniczną jest użycie granicy wszystkie komórki w połączeniu z BorderThickness i ustawienie CellSpacing pojemnika Table na 0. np

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, żal tę spóźniona odpowiedź, ale właśnie dotarłem do tego pytania. Może odpowiedź może pomóc innym.

W tym przypadku należy ustawić tabelę. Grubość obramowania na 1, tabela.CelSpacja na 0 i górna lub dolna granica dla każdej komórki.

Aby uniknąć ustawienia grubości (0,1,0,0) dla każdej komórki, można użyć stylów. Jest na to wiele sposobów, ale pokażę ci prostą. W swojej App.xaml, napisać następujące:

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

Następnie połączyć słownika aplikacji do dokumentu lub tabeli, z czymś takim:

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

można mieć style dla całego dokumentu, indywidualny stół, a nawet pojedynczy wiersz lub komórkę.

+0

jeśli komórki nie są tej samej wysokości, to masz problemy – GorillaApe

Powiązane problemy