none
flowdocument里面背景图拼接怎么消除中间的缝隙呢 RRS feed

  • 问题

  • 代码如下,用的table,构成一个9格的块

    Table t = new Table(); t.CellSpacing = 0.0;

      t.BorderThickness = new Thickness(0);

    t.Columns.Add(new TableColumn() { Width = new GridLength(42) }); t.Columns.Add(new TableColumn()); t.Columns.Add(new TableColumn(){ Width = new GridLength(20)} ); TableRow trUp = SetRowImage( new stImagePara() { path = "未标题-1_03.png" , strech = Stretch.None ,alX = AlignmentX.Right , alY = AlignmentY.Bottom}, new stImagePara() { path = "未标题-1_03-04.png", strech = Stretch.UniformToFill, alX = AlignmentX.Center, alY = AlignmentY.Bottom }, new stImagePara() { path = "未标题-1_03-05.png", strech = Stretch.None , alX = AlignmentX.Left, alY = AlignmentY.Bottom }); TableRow trMid = SetRowImage( new stImagePara() { path = "未标题-1_03-07.png", strech = Stretch.Fill, alX = AlignmentX.Right, alY = AlignmentY.Center }, new stImagePara() { path = "未标题-1_03-08.png", strech = Stretch.Fill, alX = AlignmentX.Center, alY = AlignmentY.Center }, new stImagePara() { path = "未标题-1_03-09.png", strech = Stretch.Fill, alX = AlignmentX.Left, alY = AlignmentY.Center }); TableRow trDown = SetRowImage( new stImagePara() { path = "未标题-1_03-10.png", strech = Stretch.None, alX = AlignmentX.Right, alY = AlignmentY.Top }, new stImagePara() { path = "未标题-1_03-11.png", strech = Stretch.UniformToFill, alX = AlignmentX.Center, alY = AlignmentY.Top }, new stImagePara() { path = "未标题-1_03-12.png", strech = Stretch.None, alX = AlignmentX.Left, alY = AlignmentY.Top }); TableRowGroup tg = new TableRowGroup(); tg.Rows.Add(trUp); tg.Rows.Add(trMid); tg.Rows.Add(trDown); t.RowGroups.Add(tg); TableCell tcContent = trMid.Cells[1]; tcContent.Blocks.Add(new Paragraph(new Run("aaaaaaaaaaaaa/rbbbbbbbbbbbbbbbb/rdddddddddd")) { }); return t;

    public TableRow SetRowImage(stImagePara paraImageL, stImagePara paraImageM, stImagePara paraImageR)
            {


                TableRow tr = new TableRow();

                TableCell tcL = new TableCell() { BorderThickness = new Thickness(0) , Padding = new Thickness(0)};
                TableCell tcM = new TableCell() { BorderThickness = new Thickness(0), Padding = new Thickness(0) };
                TableCell tcR = new TableCell() { BorderThickness = new Thickness(0) , Padding = new Thickness(0)};

                tr.Cells.Add(tcL);
                tr.Cells.Add(tcM);
                tr.Cells.Add(tcR);


                tcL.Background = new ImageBrush()
                {
                    ImageSource = new BitmapImage(new Uri("pack://application:,,,/" + paraImageL.path, UriKind.RelativeOrAbsolute)),
                    Stretch = paraImageL.strech,
                    AlignmentX = paraImageL.alX,
                    AlignmentY = paraImageL.alY
                    

                };

                //tcM.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#cdd7e2"));
                tcM.Background = new ImageBrush()
                {
                    ImageSource = new BitmapImage(new Uri("pack://application:,,,/" + paraImageM.path, UriKind.RelativeOrAbsolute)),
                    Stretch = paraImageM.strech,
                    AlignmentX = paraImageM.alX,
                    AlignmentY = paraImageM.alY
                };

                tcR.Background = new ImageBrush()
                {
                    ImageSource = new BitmapImage(new Uri("pack://application:,,,/" + paraImageR.path, UriKind.RelativeOrAbsolute)),
                    Stretch = paraImageR.strech,
                    AlignmentX = paraImageR.alX,
                    AlignmentY = paraImageR.alY
                };


                //tcL.Blocks.Add(new BlockUIContainer(new Image()
                //{
                //    Source = new BitmapImage(new Uri("pack://application:,,,/" + paraImageL.path, UriKind.RelativeOrAbsolute)),
                //    Width = 42,
                //    Height = 11,
                //    Tag = "pack://application:,,,/" + paraImageL.path
                //}));

               
                //tcM.Blocks.Add(new BlockUIContainer(new Image()
                //{
                //    Source = new BitmapImage(new Uri("pack://application:,,,/" + paraImageM.path, UriKind.RelativeOrAbsolute)),
                //    Height = 11,
                //    Tag = "pack://application:,,,/" + paraImageM.path,
                //    HorizontalAlignment = HorizontalAlignment.Stretch
                //}));

                //tcR.Blocks.Add(new BlockUIContainer(new Image()
                //{
                //    Source = new BitmapImage(new Uri("pack://application:,,,/" + paraImageR.path, UriKind.RelativeOrAbsolute)),
                //    Width = 42,
                //    Height = 11,
                //    Tag = "pack://application:,,,/" + paraImageR.path
                //}));

                return tr;
            }


    最后得出的效果中间会有缝隙,有没有办法把这些空隙消除呢



    2016年5月27日 2:07

全部回复

  • 您好 wpf萌新,

    >>"最后得出的效果中间会有缝隙,有没有办法把这些空隙消除呢"

    我用以下方法测试,没有出现缝隙。是不是您的图片本身的问题,图片的边缘没有处理好。

    <RichTextBox Height="300"  >
        <RichTextBox.Document>
            <FlowDocument>
                <Table CellSpacing="0" >
                    <Table.Columns>
                        <TableColumn Width="100" />
                        <TableColumn Width="auto"/>
                        <TableColumn Width="100"/>
                    </Table.Columns>
                    <Table.RowGroups>
                        <TableRowGroup>
                            <TableRow>
                                <TableCell LineHeight="50"  BorderBrush="Green" Background="Green" BorderThickness="0" Padding="0" ></TableCell>
                                <TableCell Background="Green" BorderThickness="0" Padding="0"></TableCell>
                                <TableCell Background="Green" BorderThickness="0" Padding="0"></TableCell>
                            </TableRow>
                        </TableRowGroup>
                    </Table.RowGroups>
                </Table>
            </FlowDocument>
        </RichTextBox.Document>
    </RichTextBox>
    Best Regards,
    Li Wang

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2016年5月28日 7:59
  • 我试了你的程序,确实有缝隙啊我截图了

    2016年5月30日 17:13
  • 王,有没有什么好的方法呢,不然我就只有改框架了
    2016年5月31日 7:18
  • 您好 wpf萌新,

    我这面只要不设置RichTextBox的宽度,就不会出现缝隙。设置了宽度后,不改变窗体的宽度也不会出现缝隙。这是WPF内部实现的问题。我们无法改变它。

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2016年5月31日 7:22
  • 我开始以为qq框架就是这么做的,没想到来这么一出,我故意把borderthickness设置成非0,涂上颜色,缝隙就没了,但是border和背景颜色始终有色差,就算设成一样的颜色
    2016年5月31日 7:39
  • 只有这么办了
    2016年5月31日 7:56