[C#/WPF] DependencyPropertyDescriptor 클래스 : AddValueChanged 메소드를 사용해 의존 속성 값 변경시 통지하기
C#/WPF 2020. 9. 19. 00:16■ DependencyPropertyDescriptor 클래스 : AddValueChanged 메소드를 사용해 의존 속성 값 변경시 통지하기
------------------------------------------------------------------------------------------------------------------------
▶ MainWindow.xaml
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="800" Height="600" Title="DependencyPropertyDescriptor 클래스 : AddValueChanged 메소드를 사용해 의존 속성 값 변경시 통지하기" FontFamily="나눔고딕코딩" FontSize="16"> <Grid> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> <TextBox Name="textBox" Width="200" Height="25" VerticalContentAlignment="Center" /> <TextBlock Name="textBlock" Margin="0 10 0 0" /> </StackPanel> </Grid> </Window>
|
▶ MainWindow.xaml.cs
using System; using System.ComponentModel; using System.Windows; using System.Windows.Controls;
namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent();
Loaded += Window_Loaded; Unloaded += Window_Unloaded; }
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private
#region 윈도우 로드시 처리하기 - Window_Loaded(sender, e)
/// <summary> /// 윈도우 로드시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void Window_Loaded(object sender, RoutedEventArgs e) { DependencyPropertyDescriptor descriptor = DependencyPropertyDescriptor.FromProperty ( TextBox.TextProperty, typeof(TextBox) );
if(descriptor == null) { return; }
descriptor.AddValueChanged(this.textBox, textBox_TextChanged); }
#endregion #region 윈도우 언로드시 처리하기 - Window_Unloaded(sender, e)
/// <summary> /// 윈도우 언로드시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void Window_Unloaded(object sender, RoutedEventArgs e) { DependencyPropertyDescriptor descriptor = DependencyPropertyDescriptor.FromProperty ( TextBox.TextProperty, typeof(TextBox) );
if(descriptor == null) { return; }
descriptor.RemoveValueChanged(this.textBox, textBox_TextChanged); }
#endregion #region 텍스트 박스 텍스트 변경시 처리하기 - textBox_TextChanged(sender, e)
/// <summary> /// 텍스트 박스 텍스트 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void textBox_TextChanged(object sender, EventArgs e) { TextBox textBox = sender as TextBox;
this.textBlock.Text = textBox.Text; }
#endregion } }
|
------------------------------------------------------------------------------------------------------------------------
'C# > WPF' 카테고리의 다른 글
[C#/WPF] EasingDoubleKeyFrame 엘리먼트 : EasingFunction 속성에서 CubicEase/BounceEase 객체 사용하기 (0) | 2020.09.20 |
---|---|
[C#/WPF] EasingPointKeyFrame 엘리먼트 : EasingFunction 속성에서 CubicEase/BounceEase 객체 사용하기 (0) | 2020.09.20 |
[C#/WPF] DataGridTemplateColumn 엘리먼트 : CellTemplate/CellEditingTemplate 속성 사용하기 (0) | 2020.09.19 |
[C#/WPF] XmlDataProvider 엘리먼트 : Source 속성을 사용해 XML 데이터 사용하기 (0) | 2020.09.19 |
[C#/WPF] DataGridTextColumn 엘리먼트 : 텍스트 컬럼 사용하기 (0) | 2020.09.19 |
[C#/WPF] DependencyPropertyDescriptor 클래스 : AddValueChanged 메소드를 사용해 의존 속성 값 변경시 통지하기 (0) | 2020.09.19 |
[C#/WPF] ObjectDataProvider 엘리먼트 : 열거형 타입 구하기 (0) | 2020.09.18 |
[C#/WPF] DataGrid 엘리먼트 : 커스텀 컬럼 사용하기 (0) | 2020.09.18 |
[C#/WPF] TriggerAction<T> 클래스 : 전경색 변경 액션 사용하기 (0) | 2020.09.18 |
[C#/WPF] TriggerBase<T> 클래스 : 텍스트 변경시 트리거 사용하기 (0) | 2020.09.18 |
[C#/WPF] Behavior<T> 클래스 : 배타적 익스팬더 동작 사용하기 (0) | 2020.09.18 |
댓글을 달아 주세요