Question I can't seem to find te problem, where to debug my code, is there anybody who can help me?

Eni

New member
Joined
Oct 2, 2021
Messages
1
Programming Experience
Beginner
C#:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Oefeningen
{
    /// <summary>
    /// Interaction logic for Oef6.xaml
    /// </summary>
    public partial class Oef6 : Window
    {
        public Oef6()
        {
            InitializeComponent();
        }
        private void btnCalculate_Click(object sender, RoutedEventArgs e)
        {
            double dbltxtFarenheit = Convert.ToDouble(txtFarenheit.Text);
            double dblCelcius = 5 / 9 * (dbltxtFarenheit - 32);

            txtResult.Text = "Degrees Celcius : " + dblCelcius.ToString() + "°C";
        }
    }
}

XML:
<Window x:Name="maingrid" x:Class="Oefeningen.Oef6"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Oefeningen"
        mc:Ignorable="d"
        Title="Oef6" Height="500" Width="500">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Label x:Name="lblFarenheit" Content="Give in degrees Farenheit :" HorizontalAlignment="Left" Margin="80,40,0,0" VerticalAlignment="Center"/>
        <TextBox x:Name="txtFarenheit" HorizontalAlignment="Left" Margin="284,96,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <Button x:Name="btnCalculate" Content="Convert degrees Farenheit to degrees Celcius" HorizontalAlignment="Left" Margin="80,81,0,0" Grid.Row="1" VerticalAlignment="Top" Width="250" Click="btnCalculate_Click"/>
        <TextBlock x:Name="txtResult" HorizontalAlignment="Left" Margin="80,0,0,0" Grid.Row="2" TextWrapping="Wrap" VerticalAlignment="Center" Width="200" Height="20"/>
    </Grid>
</Window>

(This is in seperate documents)
I am sorry, for the stupid question, but it is my first week learning this.
Thanks in advance.
 
Last edited by a moderator:
There's a lot of work to be done on that question to start with. I have formatted your code for readability, so please do that for us in future.

Secondly, you tell us that you there's a problem but provide no information about the problem. It's not for us to trawl through code looking for problems to fix. You need to provide a FULL and CLEAR explanation of the problem. Tell us what you're trying to achieve, show us how you're trying to achieve it, tell us what actually happens when you try it and explain how that differs from your expectations.

Finally, provide a title that summarises the issue, so we have a fairly clear idea of the problem before opening the thread. A title telling us that you have a problem that you can't solve and that you need help is of zero value because that's a given for everyone who posts here.

In summary, do all that you can do to help us help you. The less we have to do to understand the issue, the more likely you are to get the help you want and sooner.
 
Well the first problem is that you are trying to use WPF as if it were WinForms. If you want to use WinForms, use WinForms. Microsoft has givent it a second chance for life by putting it back into .NET Core for better or for worse. The learning curve will be less steep.

The second issue is the use of Hungarian notation to name your variables and controls. Hungarian was for the time when people had to know the types of objects when they had print outs of source code, or debugging in assembly code and they needed to easily identify the type of things. In the modern world, your IDE can instantly tell you the type. In fact, the .NET naming convention guidelines tells people not to use Hungarian notation.
 
Last edited:
Back
Top Bottom