绑定numericupdown [英] Binding numericupdown

查看:69
本文介绍了绑定numericupdown的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我想使用WPFToolkit.extended中的NumericUpDown创建控件.

I want to create my control using NumericUpDown from WPFToolkit.extended.

ItemsSource是值的数组.我想绑定CurrentIndex. CurrentIndex是数组ItemsSource中的索引.

ItemsSource is array of values. I want to binding CurrentIndex. CurrentIndex is a index in array ItemsSource.

 


class TAA_Up_Down : Microsoft.Windows.Controls.NumericUpDown
  {
    
    public static readonly DependencyProperty CurrentIndexProperty = DependencyProperty.Register(
      "CurrentIndex", typeof(int), typeof(TAA_Up_Down)
      );
    //private int curind;
    public int CurrentIndex
    {
      get
      {
        
        return (int)GetValue(CurrentIndexProperty);
      }
      set
      {
        if (value < 0 || this.itemsSource == null ||
          this.itemsSource.Length == 0 || this.itemsSource.Length <= value)
          return;
        //curind = value;
        SetValue(CurrentIndexProperty, value);
        InvalidateProperty(ValueProperty);
        base.Value = itemsSource[CurrentIndex];
        base.OnValueChanged(this, base.Value);

      }
    }
    private double[] itemsSource = null;
    public double[] ItemsSource
    {
      get
      {
        return itemsSource;
      }
      set
      {
        itemsSource = value;
        if (itemsSource == null || itemsSource.Length == 0)
          base.Value = "";
        else
          base.Value = itemsSource[0];
      }
    }

    public override object Value
    {
      get
      {
        if (ItemsSource == null || ItemsSource.Length == 0)
          return 0;
        return itemsSource[CurrentIndex];
      }
    }



    public TAA_Up_Down()
    {
      IsEditable = false;

    }

    protected override void OnDecrement()
    {
      if (ItemsSource == null ||
        ItemsSource.Length == 0 ||
        (CurrentIndex - 1) < 0 ||
        (CurrentIndex - 1 >= ItemsSource.Length))
        return;
      CurrentIndex--;
      base.Value = ItemsSource[CurrentIndex];
      if (ChangeValue != null)
        ChangeValue(this, new EventArgs());
    }

    protected override void OnIncrement()
    {
      if (ItemsSource == null ||
        ItemsSource.Length == 0 ||
        (CurrentIndex + 1) < 0 ||
        (CurrentIndex + 1 >= ItemsSource.Length))
        return;
      CurrentIndex++;
      base.Value = ItemsSource[CurrentIndex];
      if (ChangeValue != null)
        ChangeValue(this, new EventArgs());
      //base.OnIncrement();
    }
  }

推荐答案

 

Turkin Andrew,

 

Hi Turkin Andrew, 

似乎与绑定和通知问题有关.

It seems there is something related to binding and Notifying issue.

您能否提供有关您的问题的更多详细信息?如果您能为我们提供一个简单的现成示例,我们将很容易对其进行调试.

Could you kindly offer more details about your issue? It would be appreciated if you could offer a simple ready-to-run sample for us thus it is easy for us to debug with it.

 

谢谢!愿意帮助您!

 

最好的问候


这篇关于绑定numericupdown的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆