WPF
[WPF] WPF, Click 했을 때 새 창 띄우기
2021. 9. 21. 03:13반응형
개요
MainWindow : 처음 실행될 때, 뜨는 창
TestWindow : 클릭했을 때 뜨는 창
MainWindow.xaml
<Window x:Class="WpfApp2.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:WpfApp2"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<!--3개 Row-->
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<!--3ro Column-->
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<!--<TextBlock Text="Row : 0 Column : 0" FontSize="20" Grid.Row="0" Grid.Column="0"/>
<TextBlock Text="Row : 0 Column : 1" FontSize="20" Grid.Row="0" Grid.Column="1"/>
<TextBlock Text="Row : 1 Column : 0" FontSize="20" Grid.Row="1" Grid.Column="0"/>
<TextBlock Text="Row : 1 Column : 1" FontSize="20" Grid.Row="1" Grid.Column="1"/>-->
<Button Content="Show()" Click="ButtonShow_Click" Grid.Row="0" Grid.Column="0">
</Button>
<Button Content="ShowDialog()" Click="ButtonShowDialog_Click" Grid.Row="0" Grid.Column="1">
</Button>
</Grid>
</Window>
MainWindow.xaml.cs
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 WpfApp2
{
/// <summary>
/// MainWindow.xaml에 대한 상호 작용 논리
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void ButtonShow_Click(object sender, RoutedEventArgs e)
{
WpfApp2.TestWindow tw = new WpfApp2.TestWindow();
// 모달리스 : 뒤에있는 창으로 이동 가능
tw.Show();
}
private void ButtonShowDialog_Click(object sender, RoutedEventArgs e)
{
WpfApp2.TestWindow tw = new WpfApp2.TestWindow();
// 모달 : 해당 창을 닫기 전까지는 뒤에 있는 창으로 이동 못함
tw.ShowDialog();
}
}
}
TestWindow.xaml
<Window x:Class="WpfApp2.TestWindow"
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:WpfApp2"
mc:Ignorable="d"
Title="TestWindow" Height="450" Width="800">
<Grid>
</Grid>
</Window>
TestWindow.xaml.cs
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.Shapes;
namespace WpfApp2
{
/// <summary>
/// TestWindow.xaml에 대한 상호 작용 논리
/// </summary>
public partial class TestWindow : Window
{
public TestWindow()
{
InitializeComponent();
}
}
}
반응형