[英]Adding Image/Button Click Event Handler Dynamically in C# Silverlight
[英]Silverlight C# - Simulate a Click event on a button
我有一个带有Click方法的元素。
我想在另一个函数中激活该方法(或:伪造对此元素的单击)。
这可能吗?
不,目前没有办法。 查看链接:
https://stackoverflow.com/questions/4137528/ui-automation-for-wp7
编辑这并不能完全按照您的意愿进行,但是您可以执行类似的操作并获得相同的结果。 我在代码中大量使用了这种模式,以得到相同的结果。
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
}
在您的类中的某个地方启动RoutedEventArgs:
private RoutedEventArgs evnt;
然后稍后调用:
element_Click(element, evnt);
那应该做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.