Hi,
I have a number of charts in a dialog.
I would like to indicate which one is selected by the user, by e.g. adding a border around it.
So I thought the correct way was to use an Adorner.
But the SciChartSurface only has an AdornerLayerCanvas. It seems to be a bit different than the ususal Adoner pattern, but can it be used for this purpose, or is there a better way?
I cannot find any example either here or on google, but if you know of some, please let me know.
Thanks!
- bjarne munch asked 8 years ago
- You must login to post comments
Hi Bjarne,
Adding Adorners to the SciChartSurface should be no different than adding adorners to any other WPF control.
See the MSDN Article on Adorners
You can use some code like this to achieve it:
// Adorners must subclass the abstract base class Adorner.
public class SimpleCircleAdorner : Adorner
{
// Be sure to call the base class constructor.
public SimpleCircleAdorner(UIElement adornedElement)
: base(adornedElement)
{
}
// A common way to implement an adorner's rendering behavior is to override the OnRender
// method, which is called by the layout system as part of a rendering pass.
protected override void OnRender(DrawingContext drawingContext)
{
Rect adornedElementRect = new Rect(this.AdornedElement.DesiredSize);
// Some arbitrary drawing implements.
SolidColorBrush renderBrush = new SolidColorBrush(Colors.Green);
renderBrush.Opacity = 0.2;
Pen renderPen = new Pen(new SolidColorBrush(Colors.Navy), 1.5);
double renderRadius = 5.0;
// Draw a circle at each corner.
drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopLeft, renderRadius, renderRadius);
drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopRight, renderRadius, renderRadius);
drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomLeft, renderRadius, renderRadius);
drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomRight, renderRadius, renderRadius);
}
}
myAdornerLayer = AdornerLayer.GetAdornerLayer(sciChartSurface);
myAdornerLayer.Add(new SimpleCircleAdorner(sciChartSurface));
This should draw a box with grab-handles around the SciChartSurface. You can modify the Adorner.OnRender method to draw whatever you like.
Hope this helps!
Best regards,
Andrew
- Andrew Burnett-Thompson answered 8 years ago
- You must login to post comments
Please login first to submit.