Tugas 3 wpf namelist
Nama: Faiz Haq Noviandra Ciptadi Putra
Kelas: PBKK-B
Nrp: 5025211132
Tahun: 2023
Wpf Namelist
Pada pertemuan ini saya membuat wpf namelist seperti kita dapat manambahkan nama kita di kolom dan dapat menambah nama lebih dari 1 nama.
berikut ialah contoh ss an:
berikut merupakan source code C Sharp :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 WpfApp_NameList | |
{ | |
/// <summary> | |
/// Interaction logic for MainWindow.xaml | |
/// </summary> | |
public partial class MainWindow : Window | |
{ | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
} | |
private void btnAdd_Click(object sender, RoutedEventArgs e) | |
{ | |
if (!string.IsNullOrWhiteSpace(txtName.Text) && !lstNames.Items.Contains(txtName.Text)) | |
{ | |
lstNames.Items.Add(txtName.Text); | |
txtName.Clear(); | |
} | |
} | |
private void ButtonAddName_Click(object sender, RoutedEventArgs e) | |
{ | |
if (!string.IsNullOrWhiteSpace(txtName.Text) && !lstNames.Items.Contains(txtName.Text)) | |
{ | |
lstNames.Items.Add(txtName.Text); | |
txtName.Clear(); | |
} | |
} | |
} | |
} |
berikut merupakan source code XAML :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="WpfApp_NameList.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" | |
xmlns:local="clr-namespace:WpfApp_NameList" | |
mc:Ignorable="d" | |
Title="Names" Height="160" Width="200"> | |
<Grid Margin="10"> | |
<Grid.RowDefinitions> | |
<RowDefinition Height="*" /> | |
<RowDefinition Height="*" /> | |
</Grid.RowDefinitions> | |
<Grid.ColumnDefinitions> | |
<ColumnDefinition Width="*" /> | |
<ColumnDefinition Width="*" /> | |
</Grid.ColumnDefinitions> | |
<Label>Names</Label> | |
<ListBox Grid.Row="1" x:Name="lstNames" /> | |
<StackPanel Grid.Row="1" Grid.Column="1" Margin="5,0,0,0"> | |
<TextBox x:Name="txtName" /> | |
<Button x:Name="btnAdd" Margin="0,5,0,0" Click="ButtonAddName_Click">Add Name</Button> | |
</StackPanel> | |
</Grid> | |
</Window> |
berikut merupakan link github : Github
Komentar
Posting Komentar