LukaCiglar-4298 avatar image
0 Votes"
LukaCiglar-4298 asked LukaCiglar-4298 commented

Flowdocument Table - custom border style

Is there any option to create a custom border style for Wpf Table (type of Content Element for FlowDocuments), like create a rounded corners?

I'm thinking that It might be possible with drawing PathGeometry or using Adorner, but I don't know how to do that.

Any help much appreciated!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

gekka avatar image
0 Votes"
gekka answered LukaCiglar-4298 commented

Hi LukaCiglar,

It's not impossible, but it's difficult to do it completely ,because this cannot be handled across page boundaries.

 <Window x:Class="WpfApp1.MainWindow"
         Title="MainWindow" Height="450" Width="800">
     <Grid >
         <FlowDocumentScrollViewer >
                 <FlowDocument >
                         <Style TargetType="TableCell">
                             <Setter Property="BorderBrush" Value="Transparent"/>
                             <Setter Property="BorderThickness" Value="1,1,1,1" />
                     <Table CellSpacing="0">
                             <TableColumn Width="100"/>
                             <TableColumn Width="100" />
                             <TableColumn Width="100"/>
                         <TableRowGroup >
                             <TableRow >
                                 <TableCell RowSpan="2" BorderThickness="0" >
                                         <Canvas HorizontalAlignment="Left" VerticalAlignment="Stretch" >
                                             <Border Background="Transparent"
                                                     Loaded="Border_Loaded"  />
                                     <Paragraph >
                                         <Run >ABCDEFGHIJKLMNOPQRSTUVWXYZ</Run>
                                 <TableCell ColumnSpan="2" BorderThickness="0" >
                                     <local:BorderEx Background="LightYellow"
                                     <Paragraph Margin="5">
                                 <TableCell />
                                 <TableCell BorderBrush="Black" BorderThickness="1"/>

 namespace WpfApp1
     using System;
     using System.Collections;
     using System.Windows;
     using System.Windows.Controls;
     using System.Windows.Data;
     using System.Windows.Documents;
     using System.Windows.Media;
     public partial class MainWindow : Window
         public MainWindow()
         private void Border_Loaded(object sender, RoutedEventArgs e)
             BorderEx.Border_Loaded(sender, e);
     class BorderEx : BlockUIContainer
         public static void Border_Loaded(object sender, RoutedEventArgs e)
             Border border = (Border)sender;
             DependencyObject da = border;
             DependencyObject db = null;
             while (da != null)
                 if (da.GetType().Name == "RowVisual")
                     var cv = db as System.Windows.Media.ContainerVisual;
                     if (cv != null)
                         border.Width = cv.DescendantBounds.Width;
                         border.Height = cv.DescendantBounds.Height;
                 db = da;
                 da = VisualTreeHelper.GetParent(da);
         public BorderEx()
             this.Loaded += BorderEx_Loaded;
         private void BorderEx_Loaded(object sender, RoutedEventArgs e)
             Border border = new Border();
             border.SetBinding(Border.BorderBrushProperty, new Binding() { Path = new PropertyPath(BorderEx.BorderBrushProperty), Source = this });
             border.SetBinding(Border.BorderThicknessProperty, new Binding() { Path = new PropertyPath(BorderEx.BorderThicknessProperty), Source = this });
             border.SetBinding(Border.CornerRadiusProperty, new Binding() { Path = new PropertyPath(BorderEx.CornerRadiusProperty), Source = this });
             border.SetBinding(Border.BackgroundProperty, new Binding() { Path = new PropertyPath(BorderEx.BackgroundProperty), Source = this });
             border.Loaded += Border_Loaded;
             Canvas cv = new Canvas();
             cv.Width = 0;
             cv.Height = 0;
             cv.HorizontalAlignment = HorizontalAlignment.Left;
             cv.VerticalAlignment = VerticalAlignment.Top;
             this.Child = cv;
         public CornerRadius CornerRadius
             get { return (CornerRadius)GetValue(CornerRadiusProperty); }
             set { SetValue(CornerRadiusProperty, value); }
         public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(BorderEx), new PropertyMetadata(default(CornerRadius)));
         public new Thickness BorderThickness
             get { return (Thickness)GetValue(BorderThicknessProperty); }
             set { SetValue(BorderThicknessProperty, value); }
         public new static readonly DependencyProperty BorderThicknessProperty = DependencyProperty.Register("BorderThickness", typeof(Thickness), typeof(BorderEx), new PropertyMetadata(default(Thickness)));

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for response Gekka. Unfortunately this is not what I was hoping for. I'm looking for a solution to create border around whole Table, not just a single TableCell. And It should work for paging too.

I've tried couple of things with Adorners too, but that Is also an issue when dealing with Table that Is filled dynamically.

So I'm dropping everything, thanks for your time, cheers.

0 Votes 0 ·