-
[WPF] OnPropertyChangedC#/WPF_예제소스 2022. 7. 1. 10:50
UpdateSourceTrigger를 활용한 바인딩 업데이트 타이밍 결정 방법Permalink
UpdateSourceTriggerPermalink
Binding 클래스의 UpdateSourceTrigger 속성은 바인딩 소스 업데이트 타이밍을 결정하는 값을 가져오거나 설정할때 사용되는 속성입니다.
이것을 xaml에서 사용 하려면 다음과 같이 사용합니다.
Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}"
https://hwanine.github.io/c%23/WPF-PropertyChanged/
C# - TextBox 바인딩을 했는데 값이 바로 안바뀐다구요?
TextBox 바인딩을 하고 UpdateSourceTrigger를 활용하여 업데이트 타이밍을 지정해주어야 합니다.
hwanine.github.io
using System.ComponentModel; using System.Runtime.CompilerServices; namespace SDKSample { // This class implements INotifyPropertyChanged // to support one-way and two-way bindings // (such that the UI element updates when the source // has been changed dynamically) public class Person : INotifyPropertyChanged { private string name; // Declare the event public event PropertyChangedEventHandler PropertyChanged; public Person() { } public Person(string value) { this.name = value; } public string PersonName { get { return name; } set { name = value; // Call OnPropertyChanged whenever the property is updated OnPropertyChanged(); } } // Create the OnPropertyChanged method to raise the event // The calling member's name will be used as the parameter. protected void OnPropertyChanged([CallerMemberName] string name = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); } } }
방법: 속성 변경 알림 구현 - WPF .NET Framework
속성을 사용하도록 설정하여 WPF(Windows Presentation Foundation)에서 속성 값이 변경되면 바인딩 소스를 자동으로 알리게 합니다.
docs.microsoft.com
728x90'C# > WPF_예제소스' 카테고리의 다른 글
[WPF] foreach Control (0) 2022.08.17 [WPF]MVVM Sample (0) 2022.07.11 [WPF]모눈종이 그리기 (0) 2022.06.29 [C#]Canvas to BitmapImage (0) 2022.05.24 [C#] 열화상 이미지에 온도데이터 표출 (0) 2022.04.26 댓글