There is the button control in silverlight application . Can I send a mouse click event to it programmatically?
I've not used Silverlight but I assume it's the same process as Windows.Forms and WebControls. You'll just need to call the button's .Click(Object o, EventArgs e)
method.
You can't make the Click event fire for security reasons, because then you would be able to do things like force a user into full screen mode without them knowing it. As Oli said, you could call the Click event handler directly, but you can't actually fire a Click event.
The classic way to do this in .Net is to P/Invoke SendInput() from user32.dll, since there's no way to do this with the .Net framework.
I'm not familiar with Silverlight, but I know that it uses a compact sandbox of a .Net, so if interoperability is available, you'll find plenty examples on the internet.
I have buttons for CRUD operations in my page, after Save, Delete or Update I need Refresh the Data in a Datagrid, The most easy way was to send click event to the "Read" Button, from the Others CRUD buttons
This code fire that event:
private void btnSave_Click(object sender, RoutedEventArgs e)
{
//.....Save Operation
//--At Finish refresh the datagrid
btnRead_Click(btnRead, new RoutedEventArgs());
}
Try using Automation Peers (if you absolutely need to do this programmatically).
http://www.vbdotnetheaven.com/UploadFile/dbeniwal321/TriggerEvent01232009020637AM/TriggerEvent.aspx has a sample using vb.net
Ideal way would be to have a shared function which gets called both from button click handler as well as other cases where needed
If you still want to do that. You can now upgrade to Silverlight version 3.0 or later versions and do the following:
You can use the button automation peer from System.Windows.Automation.Peers to accomplish what you want.
if (button is Button)
{
ButtonAutomationPeer peer = new ButtonAutomationPeer((Button)button);
IInvokeProvider ip = (IInvokeProvider)peer;
ip.Invoke();
}