私は複数の部分を含むカスタムコントロールを作成しています。テンプレートの作成の内部で、私はそうのようなさまざまなイベントのためにサブスクライブしている: - どこで、どのように私はこれらのイベントから、そうであれば解除すべきであるのであればカスタムコントロール内のイベントの登録を解除するタイミング
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
this.partAreaCode = this.GetTemplateChild(PartAreaCode) as TextBox;
this.partExchange = this.GetTemplateChild(PartExchange) as TextBox;
this.partSubscriber = this.GetTemplateChild(PartSubscriber) as TextBox;
if (this.partAreaCode == null || this.partExchange == null || this.partSubscriber == null)
{
throw new NullReferenceException("Template part(s) not available");
}
this.partAreaCode.KeyDown += this.AreaKeyDown;
this.partAreaCode.TextChanged += this.AreaTextChanged;
this.partExchange.KeyDown += this.ExchangeKeyDown;
this.partExchange.TextChanged += this.ExchangeTextChanged;
this.partSubscriber.KeyDown += this.SubscriberKeyDown;
// Template might be applied after dependency property set
// lets refresh UI in this case
this.UIFromValue();
}
、私は疑問に思いますか?
私はちょうど私のコードを公開することができます誰かがそれを見直す知識:)それは私の最初のコントロールです – katit
+1それを考えていない。テンプレートを変更する場合は、未使用のPART要素をメモリに保持したくない場合があります。 – dowhilefor