private async Task UpdateAllVisualsAsync(FrameMarginProperties props) { await props.UpdateAsync(); var borderColor = props.Color; borderColor.A = props.Opacity; var borderBrush = new SolidColorBrush(borderColor); borderBrush.Freeze(); var thickness = props.Thickness; MinHeight = MinWidth = thickness; if (_isVertical) { Width = thickness; } else { Height = thickness; } Background = borderBrush; }
private EventHandler CreateHandlerForUpdateEverything(FrameMarginProperties props) { // Have to use void because it's an event handler. async void handleUpdateEverything() { // Just in case. await _initialization; await UpdateAllVisualsAsync(props); // If something goes wrong here, the only risk is it can become stuck with True forever. Not critical. _isUpdating = false; } void wrappedHandler(object sender, EventArgs e) { if (_isDisposed) { return; } if (_isUpdating) { return; } lock (_syncRoot) { if (_isUpdating) { return; } _isUpdating = true; } Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); handleUpdateEverything(); } return(wrappedHandler); }
private async Task InitializeAsync(string filePath, IWpfTextView textView) { void updateHorizontalHeight(object sender, EventArgs e) { Height = textView.ViewportHeight * (textView.ZoomLevel / 100); } var props = new FrameMarginProperties(filePath); await UpdateAllVisualsAsync(props); ClipToBounds = true; _subscriptions = new FrameMarginSubscriptions( (await Global.GetPackageAsync()).Services.MappingEvents, textView, CreateHandlerForUpdateEverything(props), updateHorizontalHeight); _subscriptions.Subscribe(_isVertical); }