问题描述
我想在Windows 8 Metro App中手动rais RichTextBlock_UpdatedLayout事件
这是一个示例代码实际代码变化很大
I want to rais RichTextBlock_UpdatedLayout event manually in Windows 8 Metro App
Here is a sample code actual code is vary big
public void rchblknew_LayoutUpdated(object sender, object e)
{
if (rchblknew.HasOverflowContent == true)
{
myspan.FontSize = 5;
rchblknew.UpdateLayout();
}
}
在同一页面我正在筹集该活动
at the same page i am raising that event
for(int i=1; i <= 3; i++)
{
rchblknew.LayoutUpdated += new EventHandler<object>(mytest_LayoutUpdated);
}
这里我期待我的活动应该是rais三次,但它只提高一次循环完成
请帮我三次rais我的事件
Here i am expecting my event should rais three time but it is raising only one time when loop is completed
Please help me to rais my event three time
推荐答案
MySpeacialEventForThisObject(this, EventArgs.Empty);
此外,大多数人包装它是为了安全和清洁
例如
Also, most people wrap it for safety and cleanliness
e.g.
private void RaiseMySpeacialEventForThisObject(MySpeacialEventData data)
{
var handler = MySpeacialEventForThisObject;
if(handler != null)
{
handler(this, data);
}
}
<pre>
现在我们有了它的方式似乎你正在尝试提出一个受保护/私人事件(大多数事件都是......实际上这是一个糟糕的设计,可能会公开事件)。您不能为UI组件执行此操作。它们由基类控制,应该是。如果你需要特殊事件,你可以经常从他们那里继承并添加你自己的事件。
Now we have that out of the way it seems you are trying to raise a protected/private event (most events are.. in fact it is bad design likely to have the event raisable publicly). You can not do that for the UI components. They are controlled by their base classes and should be. If you need speacial eventing you can often inherit from them and add your own events.
这篇关于在c#中手动提升事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!