在这篇文章里,我会示范运用DataTrigger,在纯WPF的环境下,编写一个动态的资料验证程序。这个程序所用到的编写方法,并不是很规范。为什么呢?因为程序里用了Tag这个WPF的元件属性,我的用法不太规范。不过,这个示例包含的技巧,还是值得在这儿给大家分享的。
(1)程序的图形界面:猜我喜欢的颜色--错了显示“No,try again...”,对了“Yes!!”。
<Window x:Class="WpfBindingWithCasting.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{Binding Text, ElementName=txt_bgcolor, Strin