3
코드에서 UserControl의 이벤트를 등록 할 경우. 예 :UserControl 이벤트 핸들러를 언제 릴리스해야합니까?
public partial class PositionView : UserControl
{
// If required ViewModel can be accessed using DataContext
public PositionViewModel ViewModel
{
get { return (PositionViewModel) this.DataContext; }
}
public PositionView()
{
InitializeComponent();
this.DataContextChanged += new System.Windows.DependencyPropertyChangedEventHandler(PositionView_DataContextChanged);
}
void PositionView_DataContextChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e)
{
this.ViewModel.UpdateTotalsChanged.Subscribe(_ => this.PositionGridControl.UpdateTotalSummary());
}
}
언제 이벤트 처리기를 폐기해야합니까? 후킹 할 IDisposable은 없습니까?
xaml을 통해 이벤트에 바인딩하면 수명 관리 측면에서 더 깨끗한 솔루션이됩니까?
하지만 더 일반적인 경우 키보드 이벤트 등에 연결될 수 있습니까? 내가 로컬 스코핑에 의존하기를 원하지 않을 때 – DanH
UserControl이 범위 밖의 이벤트에 바인딩해야하는 것으로 의심됩니다 (데이터 바인딩 된 장치). 키보드 이벤트는 실제로 사용자 컨트롤에서 실행되므로 사적인 범위의 이벤트도 처리 할 수 있습니다. – Aphelion