Click here to Skip to main content
15,889,838 members
Articles / Programming Languages / C#

OOP in the Real World - Creating an Equation Editor

Rate me:
Please Sign up or sign in to vote.
4.87/5 (106 votes)
21 Apr 2015MIT11 min read 137.8K   10.5K   220  
Object Oriented Design and Programming process using a real world example
<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Editor"
        x:Class="Editor.MainWindow"
        Title="MainWindow" 
        Height="550" Width="720"  
        WindowStartupLocation="CenterScreen" 
        Background="White"
        TextInput="Window_TextInput"
        KeyDown="Window_KeyDown"      
    >
    <Window.Resources>
        <Style TargetType="{x:Type Image}" x:Key="DisabledImageStyle">
            <Style.Triggers>
                <Trigger Property="IsEnabled"  Value="False">
                    <Setter Property="Opacity" Value="0.4"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Window.CommandBindings>
        <CommandBinding Command="Close"	        Executed="CloseCommandHandler"/>
        <CommandBinding Command="DecreaseZoom"  Executed="DecreaseZoomCommandHandler"/>
        <CommandBinding Command="IncreaseZoom"  Executed="IncreaseZoomCommandHandler"/>
    </Window.CommandBindings>

    <DockPanel x:Name="mainDock" LastChildFill="True">
        <Grid DockPanel.Dock="Top">            
            <Menu DockPanel.Dock="Top">
                <MenuItem x:Name="fileMenuItem" Header="_File">
                    <MenuItem x:Name="exportMenuItem" Header="_Export">
                        <MenuItem Header="_PNG" Click="exportMenuItem_Click"  Tag="png" />
                        <MenuItem Header="_JPG" Click="exportMenuItem_Click"  Tag="jpg"/>
                        <MenuItem Header="_GIF" Click="exportMenuItem_Click"  Tag="gif"/>
                        <MenuItem Header="_BMP" Click="exportMenuItem_Click"  Tag="bmp"/>
                        <MenuItem Header="_TIFF" Click="exportMenuItem_Click" Tag="tif"/>
                        <MenuItem Header="_WMP" Click="exportMenuItem_Click"  Tag="wdp"/>
                    </MenuItem>
                    <!--<MenuItem x:Name="printMenuItem" Header="_Print"    Command="Print"/>-->
                    <MenuItem x:Name="exitMenuItem" Header="E_xit"  Command="Close"/>
                </MenuItem>           
                <MenuItem x:Name="helpMenuItem" Header="_Help">                    
                    <MenuItem x:Name="contentsMenuItem" Header="_Contents (Web)" Click="contentsMenuItem_Click"/>
                    <MenuItem x:Name="supportMenuItem" Header="_Support (Web)" Click="supportMenuItem_Click"/>
                    <MenuItem x:Name="aboutMenuItem" Header="_About" Click="aboutMenuItem_Click"/>
                </MenuItem>
            </Menu>
        </Grid>
        <Grid DockPanel.Dock="Top" HorizontalAlignment="Stretch" Margin="0,2,0,4">
            <ToolBarTray  IsLocked="True">
                <ToolBar Band="1" BandIndex="1"  Height="30" Loaded="ToolBar_Loaded">
                    <Button x:Name="zoomoutButton" Command="DecreaseZoom" ToolTip="Zoom out" ToolTipService.ShowOnDisabled="True">
                        <local:AutoGreyableImage Source="images\gui\zoomout.png"/>
                    </Button>
                    <Button x:Name="zoominButton" Command="IncreaseZoom" ToolTip="Zoom in" ToolTipService.ShowOnDisabled="True">
                        <local:AutoGreyableImage Source="images\gui\zoomin.png" />
                    </Button>
                    <Separator />
                    <ToggleButton x:Name="underbarToggle" ToolTip="Show/Hide Underbar" Unchecked="underbarToggleCheckChanged" Checked="underbarToggleCheckChanged">
                        <Image Source="images\gui\underbar.png" />
                    </ToggleButton>                    
                    <Separator />
                    <Label>
                        <Hyperlink Click="meLinkClick">Download Full Version (Free)</Hyperlink>
                    </Label>
                </ToolBar>
            </ToolBarTray>
        </Grid>
        <local:MathToolBar x:Name="mathToolBar" DockPanel.Dock="Top" DockPanel.ZIndex="99"></local:MathToolBar>
        <Grid Background="#FFEEDDCC" DockPanel.Dock="Bottom" Visibility="Collapsed">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Label Name="statusBarLeftLabel" Height="25"></Label>
            <Label Grid.Column="1" Name="statusBarRightLabel" Height="25" HorizontalAlignment="Right"></Label>
        </Grid>
        <ScrollViewer x:Name="scrollViwer" FocusVisualStyle="{x:Null}" Focusable="True" ScrollChanged="scrollViwer_ScrollChanged" HorizontalScrollBarVisibility="Auto">
            <local:EditorControl Background="Transparent" x:Name="editor" Focusable="True"  FocusVisualStyle="{x:Null}"></local:EditorControl>
        </ScrollViewer>
    </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 MIT License


Written By
Technical Lead https://mathiversity.com
Unknown
I am a full-stack developer. My skills include JavaScript, C#/.Net, MS Azure cloud etc. I love to work on complex programming tasks requiring deep analysis, planning and use of efficient algorithms and data structures.

Comments and Discussions