2009-11-04 3 views
8

Bu resmi MS Word'de oluşturdum ve WPF uygulamasında stili Belgeler'i kullanarak çoğaltmaya çalışıyorum. İlk 'dan':WPF Belge: Tablo Hücre kenarlıkları sağa alma

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

Sonraki denemem çoğaltmak için:

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

Sorum muhtemelen oldukça açıktır. Neyi yanlış yapıyorum? Satır grubunda veya satırda bir dolgu özelliği bulamıyorum.

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

cevap

9

Maalesef bir FlowDocument bir TableRow için sınır ayarlayamıyor: Aşağıda benim kodudur. Yalnızca Table veya TableCell için kullanılabilir. Hatta bunun neden sağlanmadığını merak ediyorum.

bir sıra sınır etkiyi elde etmek için tek yön BorderThickness ile birlikte tüm hücrelerin sınır kullanmaktır ve eg için 0'a kabın Table arasında CellSpacing ayar rağmen: Bunun

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, üzgünüm geç cevap ama bu soruya yeni geldim. Belki cevap başkalarına yardımcı olabilir.

Bu özel durumda, bir tablo ayarlamanız gerekir. Tablo 1, tabloya. Kalınlık, 0'a ve her hücre için üst VEYA alt kenarlığına.

Her hücre için kalınlığı (0,1,0,0) olarak ayarlamaktan kaçınmak için stilleri kullanabilirsiniz. Bunu yapmanın birçok yolu var, ama size basit bir tane göstereceğim. , Bundan sonra

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

gibi bir şeyle, belgenizin veya tabloya başvuru sözlüğü birleştirme: senin App.xaml aşağıdaki bilgileri Sen bütün belge için stilleri olabilir

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

, Bireysel masa ve hatta bireysel bir satır veya hücre. Hücreler aynı yükseklikte ise

+0

o zaman sorunlarınız varsa – GorillaApe