[英]Silverlight C# - Simulate a Click event on a button
I have an element with a Click method. 我有一个带有Click方法的元素。
I would like to activate that method (or: fake a click on this element) within another function. 我想在另一个函数中激活该方法(或:伪造对此元素的单击)。
Is this possible? 这可能吗?
No, there currently isnt a way to do this. 不,目前没有办法。 See links:
查看链接:
https://stackoverflow.com/questions/4137528/ui-automation-for-wp7 https://stackoverflow.com/questions/4137528/ui-automation-for-wp7
windows phone 7: How to simulate control click programmatically Windows Phone 7:如何以编程方式模拟控件单击
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 XAML
<Button Name="testClick" Click="testClick_Click">
<TextBlock Text="Click Me"></TextBlock>
</Button>
C# 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
}
Somewhere in your class initiate a RoutedEventArgs: 在您的类中的某个地方启动RoutedEventArgs:
private RoutedEventArgs evnt;
Then later call this: 然后稍后调用:
element_Click(element, evnt);
That should do it. 那应该做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.