반응형

1. xaml

3X2의 Grid 설정

 

1-(1) xaml 소스 코드

<Window x:Class="WpfApp10.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:WpfApp10"

mc:Ignorable="d"

Title="MainWindow" Height="450" Width="800">

<Grid>

<Grid.RowDefinitions>

<RowDefinition/>

<RowDefinition/>

<RowDefinition/>

</Grid.RowDefinitions>

<Grid.ColumnDefinitions>

<ColumnDefinition/>

<ColumnDefinition/>

</Grid.ColumnDefinitions>

<Label x:Name="labelFirstName"

Grid.Column="0"

Grid.Row="0"

Content="First Name"

HorizontalAlignment="Right"

VerticalAlignment="Center"/>

<Label x:Name="labelLastName"

Grid.Column="0"

Grid.Row="1"

Content="Last Name"

HorizontalAlignment="Right"

VerticalAlignment="Center"/>

<TextBox x:Name="txtboxFirstName"

Grid.Column="1"

Grid.Row="0"

Width="120"

Height="50"

HorizontalAlignment="Left" TextChanged="txtboxFirstName_TextChanged"

/>

<TextBox x:Name="txtboxLastName"

Grid.Column="1"

Grid.Row="1"

Width="120"

Height="50"

HorizontalAlignment="Left" TextChanged="txtboLastName_TextChanged"/>

 

<TextBlock Grid.Column="0"

Grid.Row="2">

Hello<LineBreak/>

My name is...

</TextBlock>

</Grid>

</Window>

 

 

2. 이벤트 함수(Textbox의 입력에 따른 label 변화)

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 WpfApp10
{
    /// 
    /// MainWindow.xaml에 대한 상호 작용 논리
    /// 
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void txtboxFirstName_TextChanged(object sender, TextChangedEventArgs e)
        {
            labelFirstName.Content = txtboxFirstName.Text; // labelFirstName의 컨텐츠를 txtboxFirstName 텍스트로 바꿈
        }

        private void txtboLastName_TextChanged(object sender, TextChangedEventArgs e)
        {
            labelLastName.Content = txtboxLastName.Text; // labelLastName의 컨텐츠를 txtboxLastName 텍스트로 바꿈
        }
    }
}

 

 

3. 결과

반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기