Click here to Skip to main content
15,889,216 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Overiding context menu default style except for textbox contextmenu Pin
SledgeHammer014-Aug-11 8:50
SledgeHammer014-Aug-11 8:50 
QuestionHow to disable Button in RadGridView. Pin
Sunil G 33-Aug-11 20:00
Sunil G 33-Aug-11 20:00 
AnswerRe: How to disable Button in RadGridView. Pin
Mycroft Holmes4-Aug-11 13:00
professionalMycroft Holmes4-Aug-11 13:00 
QuestionError: Cannot find governing FrameworkElement for target element Pin
John-ph3-Aug-11 19:39
John-ph3-Aug-11 19:39 
QuestionSilverlight Bussines Application user authentication Pin
Eren Can Kaygusuz2-Aug-11 22:06
Eren Can Kaygusuz2-Aug-11 22:06 
AnswerRe: Silverlight Bussines Application user authentication Pin
Mycroft Holmes4-Aug-11 13:03
professionalMycroft Holmes4-Aug-11 13:03 
QuestionSilverlight Bussines Application Domain Service Pin
Eren Can Kaygusuz2-Aug-11 22:00
Eren Can Kaygusuz2-Aug-11 22:00 
QuestionMath in XAML Pin
Mc_Topaz2-Aug-11 3:15
Mc_Topaz2-Aug-11 3:15 
I would like to do some simple math in my WPF application with as much XAML code as possible and with as little C# code as possible. I have looked at various examples how to do this on diffrent web pages, but they are either to complex or don't show all details or lacks code or is just a bad example.

Please run my XAML code, just copy and paste it:
XAML
<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    
    <Window.Resources>
        <Style x:Key="Alignment">
            <Setter Property="Control.HorizontalAlignment" Value="Left"></Setter>
            <Setter Property="Control.VerticalAlignment" Value="Top"></Setter>
        </Style>
        <Style x:Key="GroupBoxStyle" BasedOn="{StaticResource Alignment}">
            <Setter Property="Control.BorderBrush" Value="Black"></Setter>
            <Setter Property="Control.BorderThickness" Value="2"></Setter>
            <Setter Property="Control.FontSize" Value="15"></Setter>
        </Style>
        <Style x:Key="Header">
            <Setter Property="Control.FontSize" Value="15"></Setter>
            <Setter Property="Control.FontWeight" Value="Bold"></Setter>
            <Setter Property="Control.Height" Value="30"></Setter>
        </Style>
    </Window.Resources>

    <Grid>
        <GroupBox Header="Product schedule" Margin="0,0,0,0" Style="{StaticResource GroupBoxStyle}"  Width="Auto" Height="Auto">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>

                <!-- Header -->
                <Label Content="Product" Grid.Row="0" Grid.Column="0" Style="{StaticResource Header}"></Label>
                <Label Content="Weight (g)" Grid.Row="0" Grid.Column="1" Style="{StaticResource Header}"></Label>
                <Label Content="Numbers" Grid.Row="0" Grid.Column="2" Style="{StaticResource Header}"></Label>
                <Label Content="Total weight (g)" Grid.Row="0" Grid.Column="3" Style="{StaticResource Header}"></Label>

                <!-- Product A -->
                <Label Content="A" Grid.Row="1" Grid.Column="0"></Label>
                <Label Content="126" Grid.Row="1" Grid.Column="1"></Label>
                <TextBox Name="txtA" Grid.Row="1" Grid.Column="2"></TextBox>
                <Label Name="lblATotalWeightGram" Grid.Row="1" Grid.Column="3"></Label>

                <!-- Product B -->
                <Label Content="B" Grid.Row="2" Grid.Column="0"></Label>
                <Label Content="220" Grid.Row="2" Grid.Column="1"></Label>
                <TextBox Name="txtB" Grid.Row="2" Grid.Column="2"></TextBox>
                <Label Name="lblBTotalWeightram" Grid.Row="2" Grid.Column="3"></Label>

                <!-- Total -->
                <Label Content="Total" Grid.Row="3" Grid.Column="0"></Label>
                <Label Name="lblPiiGABTotal" Grid.Row="3" Grid.Column="2"></Label>
                <Label Name="lblPiiGABTotalWeightGram" Grid.Row="3" Grid.Column="3"></Label>
                <Label Name="lblPiiGABTotalWeightKiloGram" Grid.Row="3" Grid.Column="4"></Label>
            </Grid>
        </GroupBox>
    </Grid>
</Window>


Notice I have two Textboxes to specify numbers of product A and product B.
I would like to calculate the following:

1) Total Weight in g for each product: A * 126 and B * 220
2) Calculate total amounth of products: A + B
3) Calculate total weight of all products: (A * 126) + (B * 220)

This should be done if I change any values in the TextBoxes.

Any help would be nice!
AnswerRe: Math in XAML Pin
dasblinkenlight2-Aug-11 5:53
dasblinkenlight2-Aug-11 5:53 
GeneralRe: Math in XAML Pin
Mc_Topaz2-Aug-11 6:22
Mc_Topaz2-Aug-11 6:22 
AnswerRe: Math in XAML Pin
Pete O'Hanlon2-Aug-11 6:08
mvePete O'Hanlon2-Aug-11 6:08 
GeneralRe: Math in XAML Pin
Mc_Topaz2-Aug-11 6:40
Mc_Topaz2-Aug-11 6:40 
GeneralRe: Math in XAML Pin
SledgeHammer012-Aug-11 7:22
SledgeHammer012-Aug-11 7:22 
QuestionClient side validation Pin
yesu prakash1-Aug-11 20:14
yesu prakash1-Aug-11 20:14 
AnswerRe: Client side validation Pin
Mycroft Holmes4-Aug-11 13:07
professionalMycroft Holmes4-Aug-11 13:07 
QuestionDistance Calculate Of A Route Pin
mrhydn1-Aug-11 3:44
mrhydn1-Aug-11 3:44 
QuestionGrid in a combo box [modified] Pin
Lutosław31-Jul-11 2:57
Lutosław31-Jul-11 2:57 
AnswerRe: Grid in a combo box Pin
teejayem31-Jul-11 6:42
teejayem31-Jul-11 6:42 
GeneralRe: Grid in a combo box Pin
Lutosław1-Aug-11 13:14
Lutosław1-Aug-11 13:14 
GeneralRe: Grid in a combo box Pin
SledgeHammer011-Aug-11 14:05
SledgeHammer011-Aug-11 14:05 
GeneralRe: Grid in a combo box [solved] Pin
Lutosław1-Aug-11 22:57
Lutosław1-Aug-11 22:57 
GeneralRe: Grid in a combo box [solved] Pin
SledgeHammer012-Aug-11 7:20
SledgeHammer012-Aug-11 7:20 
GeneralRe: Grid in a combo box [solved] Pin
Lutosław2-Aug-11 8:52
Lutosław2-Aug-11 8:52 
GeneralRe: Grid in a combo box Pin
SledgeHammer011-Aug-11 14:05
SledgeHammer011-Aug-11 14:05 
QuestionBinding: Accept an empty string in enumeration [modified] Pin
Lutosław30-Jul-11 10:24
Lutosław30-Jul-11 10:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.