Click here to Skip to main content
15,885,209 members
Articles / Desktop Programming / WPF

A Bindable WPF RichTextBox

Rate me:
Please Sign up or sign in to vote.
4.99/5 (48 votes)
13 Aug 2010CPOL14 min read 261.1K   12.6K   88  
An article about a Bindable WPF RichTextBox
<Window x:Class="FsRichTextBoxDemo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:fsc="clr-namespace:FsWpfControls.FsRichTextBox;assembly=FsRichTextBox" 
        xmlns:local="clr-namespace:FsRichTextBoxDemo"
        Title="FS RichTextBox Demo" 
        Background="PaleGoldenrod"
        Height="400" Width="600" WindowStartupLocation="CenterScreen">
    <Window.Resources>
        <!-- Value Converters -->
        <local:FlowDocumentToXamlConverter x:Key="flowDocumentConverter"/>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="200" />
            <RowDefinition Height="35" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <fsc:FsRichTextBox x:Name="EditBox" Document="{Binding Path=DocumentXaml, Converter={StaticResource flowDocumentConverter}, Mode=TwoWay}" Grid.Row="0" Margin="10,10,10,5" ToolbarBackground="#FFD2CB84" ToolbarBorderBrush="#FFC6BE75" ToolbarBorderThickness="1,1,1,0" />
        <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,5,10,5" >
            <Button Content="Load Document" Margin="0,0,10,0" Command="{Binding LoadDocument}" Width="100" />
            <Button Content="Force Update" Width="100" Margin="10,0,0,0" Click="OnForceUpdateClick" />
        </StackPanel>
        <TextBox Text="{Binding DocumentXaml}" Margin="10,5,10,10" Grid.Row="2" Background="Gainsboro" TextWrapping="Wrap">
            
        </TextBox>
    </Grid>
</Window>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Foresight Systems
United States United States
David Veeneman is a financial planner and software developer. He is the author of "The Fortune in Your Future" (McGraw-Hill 1998). His company, Foresight Systems, develops planning and financial software.

Comments and Discussions