C#/WPF
WPF (1) : 시작 창 설정, 라벨
Cathedral8293
2025. 3. 25. 14:37
// 도구상자에서 컴포넌트들을 배치할 수 있지만 코드로 배치하고 세밀한 조정을 창에서 하는 것이 빠르게 느껴진다.
1. 여러 창 중 시작 창 설정하기
<Application x:Class="WpfApp1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp1"
StartupUri="ch3.xaml"> // 여기서 원하는 xaml파일의 이름을 바꾸면 시작 창이 변경
<Application.Resources>
</Application.Resources>
</Application>
2. 비하인드 코드로 고정
namespace WpfApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
label1.Content = "HelloWorld"; // Behind 코드로 Content 설정
}
}
}
<Window x:Class="WpfApp1.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:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
// 실제 친 코드 //
<StackPanel>
<Label x:Name="label1" Content="안녕하세요.">
</Label>
<Button Content="클릭">
</Button>
<Button Content="Click">
</Button>
<Label x:Name="label2" Content="레이블">
</Label>
</StackPanel>
// /실제 친 코드 //
</Window>