Saturday, April 11, 2020

What is WPF . ? How to create WPF application step by step


What is WPF . ? How to create WPF application step by step

Step 1 – WPF UserControl Class Library 

Code Download





Step 2 – Create WPF Project for implement task using WPF UserControl Class library







Step 3 – Adding User Control




Step 4 –



Step 5



Task 1:

Create a UserControl called LoginPasswordUserControl. The LoginPasswordUserControl

contains a Label (loginLabel) that displays the string "Login:", a TextBox (loginTextBox) where the user inputs a login name, a Label (passwordLabel) that displays the string "Password:" and finally, a TextBox (passwordTextBox) where a user inputs a password.

<UserControl x:Class="Lab4.LoginPasswordUserControl"

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:local="clr-namespace:Lab4"

mc:Ignorable="d"

d:DesignHeight="450" d:DesignWidth="800">

<Grid>

<TextBox HorizontalAlignment="Left" Height="26" Margin="228,164,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="407"/>

<Label Content="UserName" Name="loginLabel" HorizontalAlignment="Left" Margin="145,164,0,0" VerticalAlignment="Top" Width="78"/>

<TextBox HorizontalAlignment="Left" Name="loginTextBox" Height="26" Margin="228,211,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="407"/>

<Label Content="Password" Name="passwordLabel" HorizontalAlignment="Left" Margin="145,211,0,0" VerticalAlignment="Top"/>

<Button Content="Login" Name="passwordTextBox" HorizontalAlignment="Left" Margin="384,300,0,0" VerticalAlignment="Top" Width="251" RenderTransformOrigin="1.002,0.246" Height="34"/>

</Grid>
</UserControl>

Task 2:

LoginPasswordUserControl must provide Public read-only properties Login and Password that allow an application to retrieve the user input from loginTextBox and passwordTextBox.

Make sure that both of the control’s properties are exposed to the developer’s form, i.e., the form that hosts the composite control LoginPasswordUserControl.





Task 3:

Use the composite control in a Windows application that will have a button (OK) and a label as shown below. Write code necessary to display the login and password entered by the user on the form. Run the program and click the OK button to display the information entered.




Task 4: Include data validation code as required.





using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Navigation;
using System.Windows.Shapes;
namespace Lab4
{
/// <summary>

/// Interaction logic for LoginPasswordUserControl.xaml

/// </summary>

public partial class LoginPasswordUserControl : UserControl
{
public LoginPasswordUserControl()
{
InitializeComponent();
}
public string loginUsrename { get; set; }
public string loginpassword { get; set; }
private void OkLogin_Click(object sender, RoutedEventArgs e)
{
string loginusrename = UsernameTextBox.Text;
string loginpass = loginTextBox.Text;
if (loginusrename == "")
{
Requiredfieldloginusenrmae.Content = "loginusrename required *";
}
if (loginpass == "")
{
Requiredfieldpassword.Content = " loginpass required *";

}
MessageBox1.Content = loginusrename + " " + loginpass;

}
}
}

No comments:

Post a Comment

Rewrite whole Web Site System and Sub System with data migration to new system.

Can you please share me your skype id or whats up number for better communications  my skype id is - jitendra.tech  whats up - +919617741414...