Click here to Skip to main content
15,897,371 members
Articles / Desktop Programming / WPF

CodeBox 2: An Extended and Improved Version of the CodeBox with Line Numbers

Rate me:
Please Sign up or sign in to vote.
4.83/5 (20 votes)
10 Oct 2009CPOL9 min read 141.2K   3.4K   65  
A WPF textbox supporting line numbering, highlighting, underlines, and strikethroughs.
<Window x:Class="ColoredWordPad.TextDocument"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:c="clr-namespace:CodeBoxControl;assembly=CodeBoxControl" 
        Loaded="Window_Loaded"
         Closing="Window_Closing"
         xmlns:cwp ="clr-namespace:ColoredWordPad"
         xmlns:p="clr-namespace:ColoredWordPad.Properties"
xmlns:sw="clr-namespace:System.Windows;assembly=PresentationCore"
xmlns:cd= "clr-namespace:CodeBoxControl.Decorations;assembly=CodeBoxControl"
    Title="TextDocument" 
    Height="{Binding Source={x:Static p:Settings.Default}, Path=Height, Mode=TwoWay}" 
    Width="{Binding Source={x:Static p:Settings.Default}, Path=Width, Mode=TwoWay}" 
    Left="{Binding Source={x:Static p:Settings.Default}, Path=Left, Mode=TwoWay}" 
    Top="{Binding Source={x:Static p:Settings.Default}, Path=Top, Mode=TwoWay}"
     >
      
    <Window.Resources>
         <cwp:SystemColorConverter x:Key="systemColorConverter"/>
        <cwp:ColorBrushConverter x:Key="colorBrushConverter"/>
        
        <c:CodeBoxSettings  x:Key="coloredWordSettings" 
     BaseColor="{Binding Source={x:Static p:Settings.Default}, Path=DefaultBaseForegroungColor, Mode=TwoWay, Converter ={StaticResource colorBrushConverter}}" />

    </Window.Resources>
    <DockPanel>
        <Menu DockPanel.Dock="Top" Name="topMenu"> </Menu>
        <ToolBarTray DockPanel.Dock="Top">
            <ToolBar>
                <Button Click="mnuTest1_Click">Test</Button>
                
                <ComboBox    ItemsSource="{Binding Source={x:Static cwp:ToolBarStatics.AvailableSchemes}}" Width="80"
                        
                              SelectedValue="{Binding ElementName=document, Path=DecorationScheme}" 
                    DisplayMemberPath="Name" Name="cmbScheme" />

                <ComboBox x:Name="cbWrap" ItemsSource="{Binding Source={cwp:EnumList {x:Type sw:TextWrapping}}}"
                       SelectedValue="{Binding ElementName=document, Path=TextWrapping}"   />     
                        
                 
               </ToolBar>
            
            
            
            
           <ToolBar>
                <ComboBox   Name="cmbColor"  Width="150"
                            SelectedIndex="32"
                    ItemsSource="{Binding Source={x:Static cwp:SystemNamedBrushes.Colors}}" >
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding  Path=.,Converter={StaticResource  systemColorConverter}}" Width="110"/>
                                <Rectangle Width="20" Height="12" Stroke="Black" StrokeThickness="1" Fill="{Binding  Path=.,Converter={StaticResource  systemColorConverter}}"/>
                            </StackPanel>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>

                <Button Name="btHilight" Click="btHilight_Click">
                    <Border Background="Yellow" >
                        <TextBlock FontWeight="Bold">H</TextBlock>
                    </Border>
                </Button>


                <Button Name="btUnderline" Click="btUnderline_Click">
                    <TextBlock FontWeight="Bold">
                      <TextBlock.TextDecorations>
                        <TextDecoration Location="Underline">
                          <TextDecoration.Pen>
                            <Pen Brush="Green"  Thickness="2" />
                          </TextDecoration.Pen>
                        </TextDecoration>
                      </TextBlock.TextDecorations>U</TextBlock>
                </Button>
                <Button   Name="btStrike" Click="btStrike_Click" >S</Button>
                <Button  Name="btTextColor"  Click="btTextColor_Click">C</Button>

            </ToolBar>
        </ToolBarTray>
            <StatusBar DockPanel.Dock="Bottom" />
        <!--<Border Name="documentBorder" 
 Background="{Binding Source={StaticResource coloredWordSettings}, Path=BackgroundColor,Converter={StaticResource  systemColorConverter}}" >-->
            <c:CodeBox Name="document" 
                BaseForeground="{Binding Source={StaticResource coloredWordSettings} ,  Path=BaseColor, Converter={StaticResource colorBrushConverter}}"
                FontSize="{Binding Source={StaticResource coloredWordSettings} ,  Path=FontSize}" 
                FontFamily="{Binding Source={StaticResource coloredWordSettings}, Path=FontFamily}"   
               CodeBoxBackground="{Binding Source={StaticResource coloredWordSettings}, Path=BackgroundColor,Converter={StaticResource  systemColorConverter}}" LineNumberMarginWidth="25"
               Text="{Binding Source={x:Static p:Settings.Default}, Path=LastText, Mode=TwoWay,  UpdateSourceTrigger=PropertyChanged}" Foreground="Transparent" />
        <!--</Border>-->
    </DockPanel>
</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)
United States United States
Written software for what seems like forever. I'm currenly infatuated with WPF. Hopefully my affections are returned.

Comments and Discussions