별도의 타겟을 지정하지 않고 Path만 써 놓으면 DataContext를 읽게 된다. DataContext는 기본적으로 null이기 때문에, 개발자가 직접 지정해주어야 한다.
<Window x:Class="IamNamespace.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"
mc:Ignorable="d"
Height="450" Width="450" Background="Black"
Title="{Binding Path=ActualWidth}">
</Window>
위는 xaml, 아래는 cs
using System.Windows;
namespace IamNamespace
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = this;
}
}
}
이렇게 하면 MainWindow의 Title에 ActualWidth를 바인딩할 수 있다.
'C# > WPF' 카테고리의 다른 글
Binding - UpdateSourceTrigger (0) | 2023.03.01 |
---|---|
RelativeSource Binding (0) | 2023.03.01 |
[C# WPF] Binding (0) | 2023.02.18 |
[C# WPF] super mario 63의 cheat를 구현해 보자. (0) | 2023.02.03 |
[C# WPF] 연속해서 여러 번 클릭하는 것을 방지해보자. (1) | 2023.01.20 |
댓글