Reputation: 6777
I have an element with a Click method.
I would like to activate that method (or: fake a click on this element) within another function.
Is this possible?
Upvotes: 0
Views: 3782
Reputation: 3054
No, there currently isnt a way to do this. See links:
https://stackoverflow.com/questions/4137528/ui-automation-for-wp7
windows phone 7: How to simulate control click programmatically
EDIT This doesnt do exactly what you wanted to do, but you can do something like this and get the same outcome. I do this type of pattern alot in my code to do get the same outcome.
XAML
<Button Name="testClick" Click="testClick_Click">
<TextBlock Text="Click Me"></TextBlock>
</Button>
C#
private void testClick_Click(object sender, RoutedEventArgs e)
{
TestFunction(sender as Button);
}
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
//Call same function as button
TestFunction(testClick);
}
private void TestFunction(Button bt)
{
//do stuff
}
Upvotes: 1
Reputation: 1822
Somewhere in your class initiate a RoutedEventArgs:
private RoutedEventArgs evnt;
Then later call this:
element_Click(element, evnt);
That should do it.
Upvotes: 0