Silverlight Binding之ConverterParameter

验证内容:
     Binding对象的ConverterParameter参数值是否有自动的时间通知,
即该变量来与一个实现INotifyPropertyChanged接口且在改变时发出改变通知的属性,当该属性改变时,
Binding对象的ConverterParameter是否会发生变化。
实现步骤: 

  第一步创建一个简单的对象:

View Code
 
  第二步创建一个集成自IValueConverter接口的对象

View Code

  

    第三步创建Binding对象,比用Timer定期改变其属性。
View Code
 
 public partial class MainPage : UserControl
    {
        System.Windows.Threading.DispatcherTimer timer 
= new System.Windows.Threading.DispatcherTimer();
        Person person 
= new Person();
        Random random 
= new Random();
        
public MainPage()
        {
            InitializeComponent();
            person.Name 
= "-1";
            AlarmColorConvert convert 
= new AlarmColorConvert();
            Binding binding 
= new Binding();
            binding.Path 
= new PropertyPath("Age"new object[0]);
            binding.Source 
= person;
            binding.Converter 
= convert;
            binding.ConverterParameter 
= person.Name;
            LayoutRoot.SetBinding(Grid.BackgroundProperty, binding);
            timer.Interval 
= TimeSpan.FromSeconds(5);
            timer.Tick 
+= new EventHandler(timer_Tick);
            timer.Start();
        }

        
void timer_Tick(object sender, EventArgs e)
        {
            person.Age 
= random.Next(0100);
            person.Name 
= person.Age.ToString();

        }
 实验结论:无论上面person对象的Age和Name如何改变AlarmColorConvert接口的parameter值始终为-1.
 即:ConverterParameter值得改变时是不会自动传递的。
 
原文地址:https://www.cnblogs.com/wangn/p/2181079.html