InlineUIContainers are removed from TableCell in RadRichTextBox when dragging a Table by mouse

3 posts, 0 answers
  1. Alexander
    Alexander avatar
    8 posts
    Member since:
    Nov 2012

    Posted 04 Dec 2012 Link to this post

    Hi everyone,

    I have a problem: I use a RadRichTextBox and in code(in runtime) by button click event I insert a Table
    with InlineUIContainers in each cell - everything is OK, but when I drag it using a Table aborner by mouse(a small cross in the left top of table) then all InlineUIContainers are removed!!! If cell contains just a Paragraph and span inside it - everithyng is OK, but
    I need to use an InlineUIContainers with a Border and TextBlock element as implemented below in method

    InitDataCell(...)

     

    private void InsertDynamicTable(DynamicTableViewModel dynamicTableViewModel)
    {
                var table = new Table();
                TableRow r1 = new TableRow();
                r1.Cells.Add(new TableCell());
                r1.Cells.Add(new TableCell());
                r1.Cells.Add(new TableCell());
                table.Rows.Add(r1);
     
                TableRow r2 = new TableRow();
                r2.Cells.Add(new TableCell());
                r2.Cells.Add(new TableCell());
                r2.Cells.Add(new TableCell());
                table.Rows.Add(r2);
     
                TableRow r3 = new TableRow();
                r3.Cells.Add(new TableCell());
                r3.Cells.Add(new TableCell());
                r3.Cells.Add(new TableCell());
                table.Rows.Add(r3);
     
                table.Tag = dynamicTableViewModel.ID.ToString();
                table.Borders = new TableBorders(new Border(dynamicTableViewModel.BorderThikness, BorderStyle.Single, dynamicTableViewModel.BorderColor));
     
                table.PreferredWidth = new TableWidthUnit(TableWidthUnitType.Fixed, dynamicTableViewModel.Width);
                table.LayoutMode = TableLayoutMode.Fixed;
     
                TableRow dataRow = table.Rows.ToArray().ToList()[1];
                List<TableCell> dataCells = dataRow.Cells.ToArray().ToList();
     
                List<double> dataCellHeights = new List<double>();
     
                for (int i = 0; i < dynamicTableViewModel.DynamicColumns.Count; i++)
                {
                    TableCell dataCell = dataCells[i];
     
                    InitHeaderCell(headerCell, dynamicTableViewModel.DynamicColumns[i]);
                          
                         //Initialize existant TableCell
                    double dataCellHeight = InitDataCell(dataCell, dynamicTableViewModel.DynamicColumns[i]);

                    dataCellHeights.Add(dataCellHeight);
                }
     
                UpdateRowHeight(dataRow, dataCellHeights);
                this.richEditor.InsertTable(table); 
                 
                this.richEditor.UpdateEditorLayout();
                this.richEditor.Document.UpdateAllFields();
                this.richEditor.Document.UpdateLayout();                 
    }
     
    private double InitDataCell(TableCell dataCell, DynamicColumnViewModel columnVm)
    {
                double cellHeight = 0;
     
                dataCell.PreferredWidth = new TableWidthUnit(TableWidthUnitType.Fixed, columnVm.Width);
                dataCell.TextAlignment = RadTextAlignment.Left;
                dataCell.VerticalAlignment = RadVerticalAlignment.Center;
                var paragraph = new Paragraph();
                paragraph.TextAlignment = RadTextAlignment.Right;
                dataCell.Blocks.Add(paragraph);
     
                dataCell.Background = columnVm.DynamicCellData.Background;
     
                Grid grid = new Grid();
     
                var tb = new TextBlock
                {
                    Text = columnVm.DbColumnName,
                    HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
                    Tag = columnVm.DbColumnName,
                    FontSize = columnVm.DynamicCellData.FontSize,
                    Background = new SolidColorBrush(columnVm.DynamicCellData.Background),
                    Foreground = new SolidColorBrush(columnVm.DynamicCellData.Foreground),
                    FontFamily = columnVm.DynamicCellData.FontFamily,
                    FontWeight = columnVm.DynamicCellData.FontWeight,
                    FontStyle = columnVm.DynamicCellData.FontStyle,
                    TextDecorations = columnVm.DynamicCellData.TextDecoration
                };
     
                tb.VerticalAlignment = VerticalAlignment.Bottom;
                tb.HorizontalAlignment = HorizontalAlignment.Right;
     
                System.Windows.Controls.Border border = new System.Windows.Controls.Border();
                border.BorderThickness = new Thickness(0);
                border.BorderBrush = Brushes.Transparent;
                border.Background = new SolidColorBrush(columnVm.DynamicCellData.Background);
                border.VerticalAlignment = VerticalAlignment.Center;
                border.HorizontalAlignment = HorizontalAlignment.Center;
                border.Child = tb;                                 
     
                border.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
     
                Size s = new Size(border.DesiredSize.Width + 1, tb.DesiredSize.Height - 1);
                var uic = new InlineUIContainer(border, s);           
     
                paragraph.Inlines.Add(uic);
     
                cellHeight = uic.Height + 5;
     
                return cellHeight;
    }

  2. Boby
    Admin
    Boby avatar
    595 posts

    Posted 05 Dec 2012 Link to this post

    Hi Alexander,
    By default InlineUIContainers are not copyable - i.e. they cannot be dragged-and-dropped, which moving table basically do. You can instead insert your custom copyable inline UI containers and check if this fits your needs:
    public class CopyableInlineUIContainer : InlineUIContainer
    {
        internal CopyableInlineUIContainer()
        {
      
        }
      
        public CopyableInlineUIContainer(UIElement uiElement, Size size)
            : base(uiElement, size)
        {
      
        }
      
        public override bool IsCopyable
        {
            get
            {
                return true;
            }
        }
      
        protected override DocumentElement CreateNewElementInstance()
        {
            return new CopyableInlineUIContainer();
        }
      
        protected override void CopyPropertiesFromOverride(DocumentElement fromElement)
        {
            CopyableInlineUIContainer fromUIContainer = (CopyableInlineUIContainer)fromElement;
            this.UiElement = fromUIContainer.UiElement;
            this.Width = fromUIContainer.Width;
            this.Height = fromUIContainer.Height;
        }
    }


    All the best,
    Boby
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Alexander
    Alexander avatar
    8 posts
    Member since:
    Nov 2012

    Posted 05 Dec 2012 Link to this post

    Hi Boby,

    Your solution is great,

    thanks for help!
Back to Top