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( 0 100 );
            person.Name 
=  person.Age.ToString();

        }
 实验结论:无论上面person对象的Age和Name如何改变AlarmColorConvert接口的parameter值始终为-1.
 即:ConverterParameter值得改变时是不会自动传递的。
 

转载于:https://www.cnblogs.com/wangn/archive/2011/09/19/2181079.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值