Skip to main content

Microsoft Silverlight

Answered Question Add formating of Textbox to TextblockRSS Feed

(0)

okaravian
okaravian

Member

Member

113 points

81 Posts

Add formating of Textbox to Textblock

 I want to Copy the text and its formating(Bold, Italic, Underline, Color etc) from textbox control to Textblock control.

How can I do this, anybody help me out.

 

example:

//this is code on click of the textblok, I want to add the text and formating contained in richTextBox in "textblock".

private void userNameLabel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.textblock.Text = richTextBox.Text.ToString();//This is for copying of text only but I want to apply th same formating as it has in richtextbox.

            ??????????????????????????????????????
        }

 

thanks in advance..... 

Mark as answered If this content leads to the correct way

regards
Nasim Ul Haq

 

jeetAbhi
jeetAbhi

Member

Member

424 points

81 Posts

Answered Question

Re: Add formating of Textbox to Textblock

If you are not adding textblock runtime then you can apply same properties (Bold, Italic, Underline, Color etc) to the textblock inside page.xaml....

<TextBox x:Name="richTextBox" Foreground="#FF366C9B" FontWeight="Bold" Width="100" Height="20" HorizontalAlignment="Left"

VerticalAlignment="Top" Text="abhijeet" FontStyle="Italic" FontFamily="Verdana"  FontSize="12" />

<TextBlock x:Name="copyBlock" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,48,0,0" Width="100" Height="20"

FontStyle="Italic" Foreground="#FF366C9B" FontFamily="Verdana" FontSize="12" />

And then just inside codebehind pass on the text as you have done above.

Or you can go this way too.........

PAGE.XAML

<TextBox x:Name="richTextBox" Foreground="#FF366C9B" FontWeight="Bold" Width="100" Height="20" HorizontalAlignment="Left"

VerticalAlignment="Top" FontStyle="Italic" FontFamily="Verdana" FontSize="12" />

<TextBlock x:Name="copyBlock" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,48,0,0" Width="100" Height="auto"

/>

<Button Height="28" HorizontalAlignment="Left" Margin="128,20,0,0" VerticalAlignment="Top" Width="32" Content="Button" x:Name="ClickMe" Click="ClickMe_Click"/>

PAGE.XAML.CS

private void ClickMe_Click(object sender, RoutedEventArgs e)

{

copyBlock.FontStyle = richTextBox.FontStyle;

copyBlock.FontWeight = richTextBox.FontWeight;

copyBlock.Foreground = richTextBox.Foreground;

copyBlock.Text = richTextBox.Text;

}

and you are done....this works for me SL 2 beta 2 and blend 2.5 june preview...

Kindly MARK AS ANSWER if this helps.........Big Smile

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities