WPF RichTextBox的Template Style问题

    在项目中实际设计中需要改变RichTextBox的UI呈现,今天在Coding的过程中发现在RichTextBox的ControlTemplate中使用ContentPresenter并不能将RichTextBox的Content呈现出来。

     查看MSDN,参见http://msdn.microsoft.com/en-us/library/ff457769(v=vs.95).aspx

     原来要将Content的呈现只需将PART_ContentHost写入Template即可。

     代码如下:

 

    <Grid>
        <RichTextBox>
            <RichTextBox.Document>
                <FlowDocument Background="AntiqueWhite">
                    <Paragraph>
                        a no space anymore between it and the second paragraph?
                    </Paragraph>
                </FlowDocument>
            </RichTextBox.Document>
            <RichTextBox.Template>
                <ControlTemplate>
                    <DockPanel LastChildFill="True">
                        <Label Background="Red" Width="50" HorizontalAlignment="Left"></Label>
                        <ScrollViewer Margin="2"
                                    x:Name="PART_ContentHost"
                                    VerticalAlignment="Stretch"
                                    HorizontalAlignment="Stretch"
                                    BorderBrush="Transparent"
                                    Background="Transparent"/>
                    </DockPanel>
                </ControlTemplate>
            </RichTextBox.Template>
        </RichTextBox>
    </Grid>

 

    效果图:

      

 

 

 

 

      转载时,请注明本文来源:www.cnblogs.com/tmywu

  

  作者: 淘米部落

      mail:tommywu23@126.com

posted @ 2012-08-06 20:35  老鱼_678  阅读(1946)  评论(0编辑  收藏  举报