【问题标题】:e.Tag DelegateCommand Bindinge.Tag DelegateCommand 绑定
【发布时间】:2012-02-15 03:59:37
【问题描述】:

我有一个小问题,找不到解决方法。我创建了一个带有命令绑定的按钮。此按钮调用 DelegateCommand,但我需要此按钮的“e.Tag”,而 DelegateCommand 只返回“null”。那么你们中有人知道解决这个问题的方法吗? 附言。 ImgSource ist 绑定到 Imagesource 所以我需要这种方式在运行时更改它。 按钮本身可以工作..

public Datenbank datab = new Datenbank();
Binding b = new Binding("GetValue");
b.Source = datab;
champbtn.SetBinding(Button.CommandProperty, b);
champbtn.Tag = path;

public class Datenbank : INotifyPropertyChanged
{
    private string _sourcep;
    public string ImgSource
    {
        get { return _sourcep; }

        set
        {
            _sourcep = value;
            NotifyPropertyChanged("ImgSource");
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(string propertyname)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyname));
    }

    public Datenbank()
    {
        GetValue = new DelegateCommand(Set);
    }

    public void Set(object sender, RoutedEventArgs e)
    {
        System.Windows.Controls.Button src = e.Source as System.Windows.Controls.Button;
        string taged = src.Tag.ToString();
        ImgSource = taged;
        //This causes an error because e == null
    }
}

【问题讨论】:

    标签: c# wpf binding delegatecommand


    【解决方案1】:

    您确定e.Source 是必要的吗?如果您在引发该事件的同一控件上处理该事件,则可以改为转换发送者。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-16
      • 1970-01-01
      • 2011-11-13
      • 1970-01-01
      • 2013-06-04
      • 1970-01-01
      • 2012-03-13
      相关资源
      最近更新 更多