글수 77
예전에 Q&A에 TextBlock에 Text가 갱신 되었을 때 배경색을 변경하는 것을 어떻게 하느냐는 질문을 올린 적이 있는데 그때는 TextBlock을 상속받은 UserControl에서 첨부 이벤트를 만들어 해결하였다는 자답을 한 적이 있습니다.
그런데 Binding 객체에는 TargetUpdated라는 첨부 이벤트가 이미 있더군요. 그러나 NotifyOnTargetUpdated 속성을 True로 해야 이벤트가 발생이 되더군요.
아래 XAML의 간단한 소스를 참고하세요.
<StackPanel Background="Transparent">
<StackPanel.Triggers>
<EventTrigger RoutedEvent="Binding.TargetUpdated">
<EventTrigger.Action>
<BeginStroyborad>
<Storyboard TargetProperty="Background.Color"/>
<ColorAnimation From="Yellow" To="Transparent" Duration="0:0:2"/>
</Storyboard>
</BeginStroyborad>
</EventTrigger.Action>
</StackPanel.Triggers>
<TextBlock Text="{Binding Text, ElementName=InputBox, Mode=OneWay, NotifyOnTargetUpdated=True}">
<TextBox x:Name="InputBox"/>
</StackPanel>
강좌라고 하기엔 너무 내용이 부실하지만 적당한 자리가 없어서... 이해해 주세요. ^^
그런데 Binding 객체에는 TargetUpdated라는 첨부 이벤트가 이미 있더군요. 그러나 NotifyOnTargetUpdated 속성을 True로 해야 이벤트가 발생이 되더군요.
아래 XAML의 간단한 소스를 참고하세요.
<StackPanel Background="Transparent">
<StackPanel.Triggers>
<EventTrigger RoutedEvent="Binding.TargetUpdated">
<EventTrigger.Action>
<BeginStroyborad>
<Storyboard TargetProperty="Background.Color"/>
<ColorAnimation From="Yellow" To="Transparent" Duration="0:0:2"/>
</Storyboard>
</BeginStroyborad>
</EventTrigger.Action>
</StackPanel.Triggers>
<TextBlock Text="{Binding Text, ElementName=InputBox, Mode=OneWay, NotifyOnTargetUpdated=True}">
<TextBox x:Name="InputBox"/>
</StackPanel>
강좌라고 하기엔 너무 내용이 부실하지만 적당한 자리가 없어서... 이해해 주세요. ^^
