diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlLanguageBinding.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlLanguageBinding.cs index 6471af3661..2108ea9bdf 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlLanguageBinding.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlLanguageBinding.cs @@ -21,6 +21,7 @@ namespace ICSharpCode.XamlBinding { XamlColorizer colorizer; TextView textView; + XamlOutlineContentHost contentHost; public override void Attach(ITextEditor editor) { @@ -38,7 +39,8 @@ namespace ICSharpCode.XamlBinding // attach the colorizer textView.LineTransformers.Add(colorizer); // add the XamlOutlineContentHost, which manages the tree view - textView.Services.AddService(typeof(IOutlineContentHost), new XamlOutlineContentHost(editor)); + contentHost = new XamlOutlineContentHost(editor); + textView.Services.AddService(typeof(IOutlineContentHost), contentHost); } // add ILanguageBinding textView.Services.AddService(typeof(XamlLanguageBinding), this); @@ -50,12 +52,13 @@ namespace ICSharpCode.XamlBinding base.Detach(); // if we added something before - if (textView != null && colorizer != null) { + if (textView != null && colorizer != null && contentHost != null) { // remove and dispose everything we added textView.LineTransformers.Remove(colorizer); textView.Services.RemoveService(typeof(IOutlineContentHost)); textView.Services.RemoveService(typeof(XamlLanguageBinding)); colorizer.Dispose(); + contentHost.Dispose(); } } } diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs index e2afa75de8..d0b57e2b5d 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs @@ -20,10 +20,9 @@ namespace ICSharpCode.XamlBinding /// <summary> /// Interaction logic for XamlOutlineContentHost.xaml /// </summary> - public partial class XamlOutlineContentHost : DockPanel, IOutlineContentHost + public partial class XamlOutlineContentHost : DockPanel, IOutlineContentHost, IDisposable { ITextEditor editor; - DispatcherTimer timer; public XamlOutlineContentHost(ITextEditor editor) { @@ -31,14 +30,10 @@ namespace ICSharpCode.XamlBinding InitializeComponent(); - this.timer = new DispatcherTimer(DispatcherPriority.Background, this.Dispatcher); - this.timer.Tick += new EventHandler(XamlOutlineContentHostTick); - - this.timer.Interval = new TimeSpan(0, 0, 2); - this.timer.Start(); + ParserService.ParseInformationUpdated += ParseInfoUpdated; } - void XamlOutlineContentHostTick(object sender, EventArgs e) + void ParseInfoUpdated(object sender, EventArgs e) { if (this.editor == null || string.IsNullOrEmpty(this.editor.FileName)) return; @@ -114,5 +109,10 @@ namespace ICSharpCode.XamlBinding return this; } } + + public void Dispose() + { + ParserService.ParseInformationUpdated -= ParseInfoUpdated; + } } } \ No newline at end of file