Visual Studio 2019 (WPF C# Source Code & XAML) How to Create a Simple Hello World Program in C# Windows Presentation Foundation (WPF App)


Visual Studio 2019 (WPF C# Source Code & XAML) How to Create a Simple Hello, World! Program in C# Windows Presentation Foundation (WPF Application).

🎓 Master Visual Basic .NET and Access Database By Building the Point Of Sale System (POS).
ðŸ“ē Enroll Now: https://bit.ly/2WcbRhX

[Visual C# Screenshot: 1]


[Visual C# Screenshot: 2]


[Visual C# YouTube Video Tutorial]


[XAML & Visual C# Code Behind]
Short link: http://bit.ly/2GfdNj0

MainWindow.xaml

<Window x:Class="SimpleHelloWorldCSWpfApp.MainWindow"
        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"
        mc:Ignorable="d"
        Title="WPF (C#) : Simple Hello, World! Program : Code A Minute : iBasskung Tutorial"
        Height="450" Width="800"
        Background="DarkCyan"
        WindowStartupLocation="CenterScreen"
        WindowState="Normal"
        WindowStyle="ThreeDBorderWindow">
 
    <Grid Margin="15">
     
        <StackPanel Orientation="Vertical"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Center">

            <TextBlock Name="resultTextBlock"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Top"
                       Text="My TextBlock"
                       TextWrapping="Wrap"
                       FontSize="100"
                       Foreground="Yellow"
                       Margin="0,0,0,30"/>

            <Button Name="sayHelloButton"
                    Content="Let's say Hello :)"
                    FontSize="72"
                    Height="140"
                    Width="740"
                    HorizontalAlignment="Stretch"
                    HorizontalContentAlignment="Center"
                    VerticalAlignment="Stretch"
                    VerticalContentAlignment="Center"
                    Background="MediumVioletRed"
                    Foreground="Gold"
                    BorderBrush="White"
                    BorderThickness="6" Click="SayHelloButton_Click"/>

        </StackPanel>
     
    </Grid>
 
</Window>

=================

MainWindow.xaml.cs

using System;
using System.Windows;

namespace SimpleHelloWorldCSWpfApp
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            resultTextBlock.Text = "...";
        }

        private void SayHelloButton_Click(object sender, RoutedEventArgs e)
        {
            // Demo by Code A Minute (iBasskung Tutorial).

            if (!resultTextBlock.Text.Equals("Hello, World!"))
            {
                resultTextBlock.Text = "Hello, World!";
            }
            else
            {
                resultTextBlock.Text = "Hello, WPF !!!";
            }

            // Ex.1
            MessageBox.Show("Hello, World! WPF Application.", "Simple WPF (C#) Hello, World! Program", MessageBoxButton.OK, MessageBoxImage.Exclamation);

            // Ex.2
            string caption = "Simple WPF (C#) Hello, World! Program";
            MessageBoxButton btnOK = MessageBoxButton.OK;
            MessageBoxImage imgInfo = MessageBoxImage.Information;

            string message = $"Hello, World!{Environment.NewLine}Hello, WPF Application!";
            MessageBox.Show(message, caption, btnOK, imgInfo);

        }
    }
}

Comments