我试图理解Dev Express示例中的代码 [这里] [1]
我想要了解的代码是
public event EventHandler RtfTextChanged;
private void richEditControl_ModifiedChanged(object sender, System.EventArgs e)
{
if(RtfTextChanged != null) // how come this is not null?
RtfTextChanged(this, EventArgs.Empty); // break at this point to display call stack.
}
[更新] 一些如何由RichEditControl设置RtfTextChanged由于它的名字。 如果我将RtfTextChanged重命名为RtfTextChanged2,则RtfTextChanged2等于null。
调用堆栈显示涉及绑定和反射
WinSolution.Module.Win.dll!WinSolution.Module.Win.RichEditUserControl.RtfText.get() Line 45 C#
[Native to Managed Transition]
System.dll!System.ComponentModel.ReflectPropertyDescriptor.GetValue(object component = {WinSolution.Module.Win.RichEditUserControl}) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Binding.GetPropValue() Unknown
System.Windows.Forms.dll!System.Windows.Forms.Binding.PullData(bool reformat = false, bool force = false) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Binding.Target_PropertyChanged(object sender, System.EventArgs e) Unknown
WinSolution.Module.Win.dll!WinSolution.Module.Win.RichEditUserControl.richEditControl_ModifiedChanged(object sender = {DevExpress.XtraRichEdit.RichEditControl}, System.EventArgs e = {System.EventArgs}) Line 63 C#
DevExpress.XtraRichEdit.v15.1.dll!DevExpress.XtraRichEdit.RichEditControl.RaiseModifiedChanged() Unknown
DevExpress.XtraRichEdit.v15.1.dll!DevExpress.XtraRichEdit.RichEditControl.OnModifiedChanged(object sender = {DevExpress.XtraRichEdit.RichEditControl}, System.EventArgs e = {System.EventArgs}) Unknown
DevExpress.RichEdit.v15.1.Core.dll!DevExpress.XtraRichEdit.Internal.InnerRichEditDocumentServer.RaiseModifiedChanged() Unknown
DevExpress.RichEdit.v15.1.Core.dll!DevExpress.XtraRichEdit.Internal.InnerRichEditDocumentServer.OnModifiedChanged(object sender = {DevExpress.XtraRichEdit.Model.DocumentModel}, System.EventArgs e = {System.EventArgs}) Unknown
DevExpress.RichEdit.v15.1.Core.dll!DevExpress.XtraRichEdit.Model.DocumentModel.RaiseModifiedChanged() Unknown
DevExpress.RichEdit.v15.1.Core.dll!DevExpress.XtraRichEdit.Model.DocumentModel.OnHistoryModifiedChanged(object sender = {DevExpress.XtraRichEdit.Model.History.RichEditDocumentHistory}, System.EventArgs e = {System.EventArgs}) Unknown
DevExpress.Office.v15.1.Core.dll!DevExpress.Office.History.DocumentHistory.RaiseModifiedChanged() Unknown
DevExpress.Office.v15.1.Core.dll!DevExpress.Office.History.DocumentHistory.EndTrackModifiedChanged() Unknown
DevExpress.Office.v15.1.Core.dll!DevExpress.Office.History.DocumentHistory.InternalAdd(DevExpress.Office.History.HistoryItem item = {DevExpress.XtraRichEdit.Model.History.RichEditCompositeHistoryItem}) Unknown
DevExpress.Office.v15.1.Core.dll!DevExpress.Office.History.DocumentHistory.Add(DevExpress.Office.History.HistoryItem item = {DevExpress.XtraRichEdit.Model.History.RichEditCompositeHistoryItem}) Unknown
DevExpress.RichEdit.v15.1.Core.dll!DevExpress.XtraRichEdit.Model.History.RichEditDocumentHistory.Add(DevExpress.Office.History.HistoryItem item = {DevExpress.XtraRichEdit.Model.History.RichEditCompositeHistoryItem}) Unknown
DevExpress.Office.v15.1.Core.dll!DevExpress.Office.History.DocumentHistory.CommitTransaction() Unknown
DevExpress.Office.v15.1.Core.dll!DevExpress.Office.History.DocumentHistory.EndTransaction() Unknown
DevExpress.Office.v15.1.Core.dll!DevExpress.Office.History.HistoryTransaction.Dispose(bool disposing = true) Unknown
DevExpress.Office.v15.1.Core.dll!DevExpress.Office.History.HistoryTransaction.Dispose() Unknown
DevExpress.RichEdit.v15.1.Core.dll!DevExpress.XtraRichEdit.Commands.TransactedMultiCommand.ForceExecute(DevExpress.Utils.Commands.ICommandUIState state = {DevExpress.Utils.Commands.DefaultCommandUIState}) Unknown
DevExpress.Data.v15.1.dll!DevExpress.Utils.Commands.Command.Execute() Unknown
DevExpress.RichEdit.v15.1.Core.dll!DevExpress.XtraRichEdit.Keyboard.NormalKeyboardHandler.FlushPendingTextInputCore(string pendingInput = "x") Unknown
DevExpress.RichEdit.v15.1.Core.dll!DevExpress.XtraRichEdit.Keyboard.NormalKeyboardHandler.PerformFlushPendingTextInput(string pendingInput = "x") Unknown
DevExpress.RichEdit.v15.1.Core.dll!DevExpress.XtraRichEdit.Keyboard.NormalKeyboardHandler.FlushPendingTextInput() Unknown
DevExpress.RichEdit.v15.1.Core.dll!DevExpress.XtraRichEdit.Internal.InnerRichEditControl.FlushPendingTextInput() Unknown
DevExpress.XtraRichEdit.v15.1.dll!DevExpress.XtraRichEdit.RichEditControl.ForceFlushPendingTextInput() Unknown
DevExpress.XtraRichEdit.v15.1.dll!DevExpress.XtraRichEdit.RichEditControl.OnFlushPendingTextInputTimerTick(object sender = {Interval = 100}, System.EventArgs e = {System.EventArgs}) Unknown
DevExpress.XtraRichEdit.v15.1.dll!DevExpress.XtraRichEdit.Drawing.LeakSafeEventRouter.OnFlushPendingTextInputTimerTick(object sender = {Interval = 100}, System.EventArgs e = {System.EventArgs}) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Timer.TimerNativeWindow.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 275, System.IntPtr wparam, System.IntPtr lparam) Unknown
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason, int pvLoopData) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) Unknown
DevExpress.ExpressApp.Win.v15.1.dll!DevExpress.ExpressApp.Win.WinApplication.DoApplicationRun() Unknown
DevExpress.ExpressApp.Win.v15.1.dll!DevExpress.ExpressApp.Win.WinApplication.Start() Unknown
WinSolution.Win.exe!WinSolution.Win.Program.Main() Line 46 C#
[Native to Managed Transition]
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() Unknown
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() Unknown
我在RichEditControl源中看到了
#if !SL
[DevExpressXtraRichEditLocalizedDescription("RichEditControlRtfTextChanged")]
#endif
public event EventHandler RtfTextChanged {
add { if (InnerControl != null) InnerControl.RtfTextChanged += value; }
remove { if (InnerControl != null) InnerControl.RtfTextChanged -= value; }
}
答案 0 :(得分:0)
我想如果我想在另一个班级中提出一个事件,那么我需要为该事件设置一个汉堡。
我是通过使用活动的名称
来做到这一点的public event EventHandler RtfTextChanged;
另一个类中的某些东西已经订阅的事实意味着处理程序不会为null。