■ Binding 클래스을 사용하는 방법을 보여준다.
▶ Dog.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
/// <summary> /// 개 /// </summary> public class Dog { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 개 이름 - DogName /// <summary> /// 개 이름 /// </summary> public string DogName { get; set; } #endregion } |
▶ MainPage.xaml
1 2 3 4 5 6 7 |
<Grid x:Name="grid" Background="White"> <TextBlock x:Name="textBlock" Text="Test" /> </Grid> |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
using System.Windows.Data; ... Dog dog = new Dog(); dog.DogName = "Spot"; ... Binding binding = new Binding(); binding.Path = new PropertyPath("DogName"); binding.Mode = BindingMode.OneTime; binding.Source = dog; // 또는 textBlock.DataContext = dog; ... this.textBlock.SetBinding(TextBlock.TextProperty, binding); |