Binding이란? WPF에서 쓸 수 있는 기술이다. 쓰는 방법은 무척 간단하다.
<Window x:Class="WPFTEST.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:WPFTEST"
mc:Ignorable="d"
Title="{Binding ElementName=asdf, Path=ActualHeight}" Height="450" Width="800" Background="Black" x:Name="asdf">
</Window>
큰 따옴표 안에 {Binding}을 써 주기만 하면 끝이다.
Binding을 사용할 수 있는 가장 단순하고 쉬운 방법은 ElementName을 지정한 후 그 Element의 속성을 Path로 지정해주는 것이다. 실제로 저 프로그램을 실행해보면...
프로그램 창의 Title이 ActualWidth와 실시간으로 동기화되는 것을 볼 수 있다.
'C# > WPF' 카테고리의 다른 글
RelativeSource Binding (0) | 2023.03.01 |
---|---|
DataContext Binding (0) | 2023.03.01 |
[C# WPF] super mario 63의 cheat를 구현해 보자. (0) | 2023.02.03 |
[C# WPF] 연속해서 여러 번 클릭하는 것을 방지해보자. (1) | 2023.01.20 |
[C# WPF] Ctrl Z 감지하기 (0) | 2023.01.09 |
댓글