Click here to Skip to main content
13,046,562 members (70,019 online)
Click here to Skip to main content

Stats

89.1K views
3.6K downloads
154 bookmarked
Posted 7 Nov 2010

Equation Calculator with Graphing

, 25 Nov 2010
Equation Calculator with Graphing
CommonUtils
bin
Debug
CommonUtils.dll
Color
Equation
GraphicalCanvas
Properties
Themes
Calculator
Calculator
bin
Debug
Calculator.exe
Calculator.vshost.exe
Calculator.vshost.exe.manifest
CommonUtils.dll
Graphing
Properties
Calculator.suo
CommonUtils.dll
Calculator.exe
Calculator.vshost.exe
Calculator.vshost.exe.manifest
CommonUtils.dll
Calculator.suo
Calculator.application
Calculator.exe
Calculator.exe.manifest
Calculator.vshost.application
Calculator.vshost.exe
Calculator.vshost.exe.manifest
CommonUtils.dll
Calculator.csproj.user
Calculator.csproj.vspscc
MSSCCPRJ.SCC
Calculator.suo
Calculator.vssscc
MSSCCPRJ.SCC
CommonUtils.dll
CommonUtils.csproj.vspscc
MSSCCPRJ.SCC
Release
CommonUtils.csproj.vspscc
MSSCCPRJ.SCC
Calculator.application
Calculator.exe
Calculator.exe.manifest
Calculator.vshost.application
Calculator.vshost.exe
Calculator.vshost.exe.manifest
CommonUtils.dll
Calculator.csproj.user
Calculator.csproj.vspscc
MSSCCPRJ.SCC
Calculator.suo
Calculator.vssscc
MSSCCPRJ.SCC
<UserControl x:Class="Calculator.CalculatorCtrl"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
            xmlns:shared="clr-namespace:CommonUtils;assembly=CommonUtils"
            xmlns:local="clr-namespace:Calculator"
            mc:Ignorable="d" 
            d:DesignHeight="325" d:DesignWidth="471">
    <UserControl.Resources>

        <Style TargetType="ListBoxItem">
            <Style.Resources>
                <!-- 
http://blogs.msdn.com/b/wpfsdk/archive/2007/08/31/specifying-the-selection-color-content-alignment-and-background-color-for-items-in-a-listbox.aspx
-->
                <!--SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightGreen"/-->
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#fF242424"/>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FF545454"/>
            </Style.Resources>
            <Setter Property="Foreground" Value="{StaticResource Forecolor}" />
        </Style>

        <DataTemplate DataType="{x:Type shared:EquationParser}">
            <shared:DockWrapPanel Margin="0,-2,0,-2">
                <Label Content="{Binding Equation}" VerticalContentAlignment="Center" Margin="0,0,10,0"/>
                <Label Content="{Binding UsedVarsAsString}" 
                    VerticalContentAlignment="Bottom" FontSize="10" />
                <StackPanel DockPanel.Dock="Right" Orientation="Horizontal" FlowDirection="RightToLeft">
                    <Label Content="{Binding ValueAsString}" MinWidth="20" VerticalContentAlignment="Center" FlowDirection="LeftToRight"/>
                    <Label Content="=" VerticalContentAlignment="Center"/>
                </StackPanel>
            </shared:DockWrapPanel>
        </DataTemplate>

        <SolidColorBrush x:Key="infocolor" Color="Wheat" />
        <shared:VisibilityConverter x:Key="visConv" />

    </UserControl.Resources>
    <Grid >
        <Grid.RowDefinitions>
            <RowDefinition Height="214*" />
            <RowDefinition Height="101" />
        </Grid.RowDefinitions>
        <ListBox ItemsSource="{Binding Stack}" HorizontalContentAlignment="Stretch" 
            ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
            x:Name="m_stackView" Background="Black" TabIndex="4" PreviewKeyDown="OnListboxPreviewKeyDown" />
        <StackPanel Grid.Row="1" Margin="10,0,10,0">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="Expression" FontFamily="Calibri" FontSize="14" 
                    Foreground="{StaticResource infocolor}" VerticalAlignment="Center"/>
                <TextBlock Margin="8,0,0,0" FontFamily="Calibri" FontSize="12" 
                    Foreground="{StaticResource infocolor}" VerticalAlignment="Center"
                    Visibility="{Binding ElementName=m_input, Path=IsFocused, Converter={StaticResource visConv}}">
                    Enter expression, &lt;Enter&gt; to calculate
                </TextBlock>
            </StackPanel>
            <DockPanel>
                <Button Margin="3,0,0,0" Width="50" VerticalAlignment="Stretch" Click="OnInsertFunction"
                    Style="{StaticResource StyleBlackButton}" TabIndex="2" DockPanel.Dock="Right" x:Name="m_funcButton">Func</Button>
                <Button Margin="3,0,0,0" Width="50" VerticalAlignment="Stretch" Click="OnCalculate"
                    Style="{StaticResource StyleBlackButton}" TabIndex="1" DockPanel.Dock="Right">Calc</Button>
                <shared:TextBoxWithHistory Text=""
                    Name="m_input" 
                    VerticalAlignment="Top"
                    HorizontalAlignment="Stretch"
                    FontSize="16"
                    KeyDown="OnInputKeyDown"
                    SelectionBrush="LightGray"
                    CaretBrush="{Binding RelativeSource={RelativeSource Self}, Path=Foreground}" TabIndex="0">
                </shared:TextBoxWithHistory>
            </DockPanel>
            <StackPanel Orientation="Horizontal" Margin="0,8,0,0">
                <TextBlock Text="Constants" FontFamily="Calibri" FontSize="14" 
                    Foreground="{StaticResource infocolor}" VerticalAlignment="Center"/>
                <TextBlock Margin="8,0,0,0" FontFamily="Calibri" FontSize="12" 
                    Foreground="{StaticResource infocolor}" VerticalAlignment="Center"
                    Visibility="{Binding ElementName=m_variables, Path=IsFocused, Converter={StaticResource visConv}}">
                    Semicolon seperated list e.g. 'x=10; y=pi/2'
                </TextBlock>
            </StackPanel>
            <Border>
                <Border.Resources>
                    <Style x:Key="DropButtonStyle" TargetType="Button" BasedOn="{StaticResource StyleBrownButton}">
                    </Style>
                </Border.Resources>
                <shared:TextBoxWithHistory Text="" HorizontalAlignment="Stretch" 
                        Name="m_variables" 
                        VerticalAlignment="Top"
                        FontSize="12"
                        SelectionBrush="LightGray"
                        CaretBrush="{Binding RelativeSource={RelativeSource Self}, Path=Foreground}" 
                        TabIndex="3">
                    <shared:TextBoxWithHistory.Resources>
                    </shared:TextBoxWithHistory.Resources>
                </shared:TextBoxWithHistory>
            </Border>
        </StackPanel>
    </Grid>
</UserControl>

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)

Share

About the Author

jkristia
Software Developer (Senior)
United States United States
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170713.1 | Last Updated 25 Nov 2010
Article Copyright 2010 by jkristia
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid