0

少し問題があり、それを修正する方法が見つかりません。Commandbinding で Button を作成します。このボタンは DelegateCommand を呼び出しますが、このボタンの「e.Tag」が必要であり、DelegateCommand は「null」を返すだけです。それで、これを解決する方法を知っている人はいますか?ps。ImgSource は 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
    }
}
4

1 に答える 1

0

それが必要だと確信していますe.Sourceか?イベントを発生させた同じコントロールでイベントを処理する場合は、代わりに送信者をキャストできます。

于 2012-02-15T08:50:29.023 に答える