torun
torun

Reputation: 480

Why doesn't xbutton.PerformClick() work in silverlight?

I need Button.click from another class but doesn't work pickButton.PerformClick()?

[Category("Özel")]
[DefaultValue(null)]
public Button pickButton { get; set; }


protected override void OnKeyUp(KeyEventArgs e)
{
    base.OnKeyUp(e);
    if (e.Key == Key.F10)
    {
        if (pickButton != null)
        {
            //pickButton.PerformClick() ??
        }
    }
}

Upvotes: 0

Views: 927

Answers (2)

mugume david
mugume david

Reputation: 635

Silverlight does not support that operation. Call the click event directly i.e

pickButton.pickButton_Click(this, null);

or

 button2_Click(this, null);

Upvotes: 2

ChrisF
ChrisF

Reputation: 137148

PerformClick isn't available in Silverlight.

Why don't you extract the code from the pickButton click event and call that from both places:

protected override void OnKeyUp(KeyEventArgs e)
{
    base.OnKeyUp(e);
    if (e.Key == Key.F10)
    {
        if (pickButton != null)
        {
            DoStuff();
        }
    }
}

and:

private void pickButton_OnClick(object sender, RoutedEventArgs e)
{
    DoStuff();
}

Obviously DoStuff() is a placeholder to illustrate the concept.

Upvotes: 3

Related Questions