locked
RitchTextBox Color Dynamic Resources RRS feed

  • Question

  • When I use following FlowDocument in the demo VSPackage project it isn't rendered in RichTextBox at all. And even I define BlackColor in resource dictionary(<RichTextBox.Resources><Color x:Key="BlackColor">Black</Color></RichTextBox.Resources>), I have unexpected behaviour with copy/paste operation. I created this flow document using standart manipulation in runtime. 

            <StackPanel Orientation="Vertical">
                <TextBlock Margin="10" HorizontalAlignment="Center">My Tool Window</TextBlock>
                <Button Content="_Click Me!" Click="button1_Click" Width="120" Height="80" Name="button1"/>
                <RichTextBox Height="400">
                    <FlowDocument>
                        <Section>
                            <Section.Foreground>
                                <SolidColorBrush Color="{DynamicResource BlackColor}" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />
                            </Section.Foreground>
                            <Paragraph>
                                <Run>l,;,l;,l,;l,;l,ll;,l,;l,</Run>
                                <Run>
                                    <Run.Foreground>
                                        <SolidColorBrush Color="{DynamicResource BlackColor}" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />
                                    </Run.Foreground> ;l,lrfrfffffffffffffffffffffffffffffffffffff
                                </Run>
                            </Paragraph>
                        </Section>
                    </FlowDocument>
                </RichTextBox>
            </StackPanel>
        

    My vs config: cofig



    Sunday, November 18, 2012 11:57 AM

All replies

  • Did it a custom control? Can we debug it? Where you define the RichTextBox.Resources, I can't find it from you example?

    I think what you asked was more related WPF, was it?


    崖山之後無中國,明亡之後無華夏

    Monday, November 19, 2012 8:55 AM
  • Hi Disley, no it's default autogenerated BaseToolWindow(UserControl). I'll send solution if needed, but there is nothing special.

    >>Where you define the RichTextBox.Resources,

    directly under the RichTextBox tag, but if I define it in higher lvl tag it is the same story.  

    <RichTextBox Height="400">

    <RichTextBox.Resources><Color x:Key="BlackColor">Black</Color></RichTextBox.Resources>

    >>I think what you asked was more related WPF, was it?

    I checked same richrtextbox cofiguration on a desktop wpf application and it works fine. 


    Monday, November 19, 2012 12:11 PM
  • Hi Ivan,

    I will involve some experts into this issue to see whether they can help you out. There might be some time delay, appreciate for your patience.
     
    Thank you for your understanding and support.
     
    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, November 20, 2012 8:51 AM
  • Hi Ivan,

    Have you tried to add modified code piece by piece and delete x:Key , eg:

    <RichTextBox Height="400">

    <RichTextBox.Resources><Color >Black</Color></RichTextBox.Resources>

    </RichTextBox >

    or just like this:

    <RichTextBox Height="400" Color="Black">

    </RichTextBox >

    did above work?

    Best Regards,

    Jenny

    Thursday, November 22, 2012 9:40 AM
  • Hy Jenny,

    as I know, RichTextBox from wpf PresentationFramework hasn't property Color, and adding color object into resources whithout a key will not make any good job for sure.   

    Thursday, November 22, 2012 7:15 PM
  • Hi Ivan,

    sorry not to notice in WPF, then have a try:

     <RichTextBox>
                <RichTextBox.Resources>
                    <Style TargetType="{x:Type Paragraph}">
                        <Setter Property="Margin" Value="0"/>
                        <Setter Property="Background" Value="Azure"/>
                    </Style> 
                </RichTextBox.Resources>
                
                <FlowDocument>
                    <Paragraph>
                        This is my first paragraph... see how there is...
                    </Paragraph>
                    <Paragraph>
                        a no space anymore between it and the second paragraph?
                    </Paragraph>
                </FlowDocument>
            </RichTextBox>
     

    and have a refferece to this document: http://msdn.microsoft.com/en-us/magazine/cc163371.aspx

    Regards,

    Jenny

     

    Friday, November 23, 2012 3:43 AM
  • your example works good, I have two paragraphs with azure background ^_^. What about my document with dynamic BlackBrush? Why do I get so inconvenient results?

    I have to say, that I found a workaround for particular problem. I define a default style for section and run elements and set the foreground property in black (thx, for your last post). So it becomes difficult to create such kind of documents. 


    Sunday, November 25, 2012 9:28 PM
  • Hi Ivan,

    Seen from your description, then you have a try:

     <Grid>
            <RichTextBox>
                <RichTextBox.Resources>
                    <Style TargetType="{x:Type Paragraph}"  x:Key="ParagraphStyle1">
                        <Setter Property="Margin" Value="0"/>
                        <Setter Property="Background" Value="Azure"/>
                    </Style>
                    <Style  TargetType="{x:Type Section}"
                        x:Key="SectionStyle1">
                        <Setter Property="FontSize" Value="26"/>
                        <Setter Property="Foreground" Value="Black"/>                        
                    </Style>
                    <Style  TargetType="{x:Type Run}"
                        x:Key="RunStyle1">
                        <Setter Property="FontSize" Value="26"/>
                        <Setter Property="Foreground" Value="Red"/>
                    </Style>
                </RichTextBox.Resources>
                
                <FlowDocument>
                    <Paragraph Style="{StaticResource ParagraphStyle1}">
                        This is my first paragraph... see how there is...
                    </Paragraph>
                    <Paragraph>
                        a no space anymore between it and the second paragraph?
                    </Paragraph>
                    <Section Style="{StaticResource SectionStyle1}">
                        <Paragraph>
                            <Run>l,;,l;,l,;l,;l,ll;,l,;l,</Run>
                        </Paragraph>
                        <Paragraph>
                            <Run Style="{StaticResource RunStyle1}">l,;,l;,l,;l,;l,ll;,l,;l,</Run>
                        </Paragraph>
                    </Section>
                </FlowDocument>
            </RichTextBox>
        </Grid>

    Regards,

    Jenny


    Wednesday, December 26, 2012 2:49 AM