Why does Winforms.Button.Text work for a DataBinding but not ImageKey?

Is there anyone who knows this?

I tried this last week and no luck.

Now I see that once you can successfully bind the Button Text property, but not its ImageKey property:

myButton.Text = "new text"; // really changes the bound data
myButton.ImageKey = "new text"; // does NOT change the bound data

I use:

myButton.DataBindings.Add ( new Binding ( "ImageKey", this.MyData, "Name", true, DataSourceUpdateMode.OnPropertyChanged ) );

Why? What makes Binding tick / work? I just do not understand.

EDIT:

OK, so I defined them for my own derived control:

public event EventHandler ImageKeyChanged;

protected virtual void OnImageKeyChanged ( EventArgs e )
{
    if ( ImageKeyChanged!= null )
    {
        ImageKeyChanged ( this, e );
    }
}

[Bindable ( true )]
public new string ImageKey
{
    get
    {
        return base.ImageKey;
    }
    set
    {
        base.ImageKey = value;
        this.OnImageKeyChanged ( EventArgs.Empty );
    }
}

It still does not work. Is there a tutorial or something on the net that shows this. It just doesn't work for me.

+2
source share
2 answers

... DOES NOT modify associated data

, - :

  • a public event EventHandler {name}Changed;, {name} - (ImageKeyChanged, )
  • INotifyPropertyChanged

, , ; , . , TextChanged, ImageKeyChanged.

+3

(TextChanged Text) INotifyPropertyChanged. Button ImageKeyChanged, .

+2

Source: https://habr.com/ru/post/1721239/


All Articles