mrfangzheng

Hope and fear are useless. Be confident, and always be prepared for the worst.
  首页  :: 新随笔  :: 联系 :: 管理

WPF : UserControl的Initialized事件不会触发

Posted on 2009-11-25 10:02  mrfangzheng  阅读(779)  评论(0编辑  收藏  举报

UserControl必须实现ISupportInitialize接口.

 

 

/// <summary>
/// Implement ISupportInitialize so that the Initialized event can be attached in XAML.
/// A known bug is that the BeginInit/EndInit will be called twice in WPF 3.*.
/// </summary>

public partial class UcTaskItemNote : ISupportInitialize
{
    
private int mInitCalledCount = 0;

    
#region ISupportInitialize Members

    
void ISupportInitialize.BeginInit()
    {       
        
if(this.mInitCalledCount == 0)
        {
            
return;
        }
        
base.BeginInit();
    }

    
void ISupportInitialize.EndInit()
    {
        
if (this.mInitCalledCount == 0)
        {
            
this.mInitCalledCount++;
            
return;
        }
        
base.EndInit();
    }

    
#endregion
}