Hey Guys,
On a SciChart surface (CandleStickChart), how could I add LineAnnotation, BoxAnnotation, and TextBox annotation using TradingAnnotationCreationModifierMvvm (available under
ChartAnnotations/Trade Annotations sample). I have recreated a sample, based on the example.
Following is my XAML code,
Chart Surface: Modifiers.
<s:TradingAnnotationCreationModifierMvvm AnnotationViewModelType="{Binding DataContext.AnnotationCreationVM.AnnotationType, Source={StaticResource ROOT_OHLC_CHART_SPY}}"
AnnotationViewModelsCollection="{Binding LAnnotations}"
IsEnabled="{Binding DataContext.AnnotationCreationVM.IsAnnotationCreationEnable, Source={StaticResource ROOT_OHLC_CHART_SPY}, Mode=TwoWay}"
ReceiveHandledEvents="True">
<i:Interaction.Behaviors>
<ext:EventToCommandBehavior Command="{Binding DataContext.AnnotationCreationVM.AnnotationCreatedCommand, Source={StaticResource ROOT_OHLC_CHART_SPY}}"
Event="AnnotationCreated"
PassArguments="True" />
</i:Interaction.Behaviors>
</s:TradingAnnotationCreationModifierMvvm>
ParentView Buttons,
<ToggleButton Width="Auto" HorizontalAlignment="Stretch" Content="Line"
Style="{StaticResource ChartToggleButton}"
IsChecked="{Binding AnnotationCreationVM.Line}"
CommandParameter="{x:Type s:LineAnnotationViewModel}"/>
<ToggleButton Width="Auto" HorizontalAlignment="Stretch" Content="Elliot Wave" Grid.Row="1"
Style="{StaticResource ChartToggleButton}"
IsChecked="{Binding AnnotationCreationVM.EllioteWave}"
CommandParameter="{x:Type dt:ElliotWaveAnnotationViewModel}"/>
<ToggleButton Width="Auto" HorizontalAlignment="Stretch" Content="Pitch Fork" Grid.Row="2"
Style="{StaticResource ChartToggleButton}"
IsChecked="{Binding AnnotationCreationVM.PitchFork}"
CommandParameter="{x:Type dt:PitchforkAnnotationViewModel}"/>
<ToggleButton Width="Auto" HorizontalAlignment="Stretch" Content="Xabcd" Grid.Row="3"
Style="{StaticResource ChartToggleButton}"
IsChecked="{Binding AnnotationCreationVM.Xabcd}"
CommandParameter="{x:Type dt:XabcdAnnotationViewModel}"/>
<ToggleButton Width="Auto" HorizontalAlignment="Stretch" Content="Head N Shoulders" Grid.Row="4"
Style="{StaticResource ChartToggleButton}"
IsChecked="{Binding AnnotationCreationVM.Hns}"
CommandParameter="{x:Type dt:HeadAndShouldersAnnotationViewModel}"/>
<ToggleButton Width="Auto" HorizontalAlignment="Stretch" Content="Fibonacci Extension" Grid.Row="5"
Style="{StaticResource ChartToggleButton}"
IsChecked="{Binding AnnotationCreationVM.FibExt}"
CommandParameter="{x:Type dt:FibonacciExtensionAnnotationViewModel}"/>
<ToggleButton Width="Auto" HorizontalAlignment="Stretch" Content="Fibonacci Retracement" Grid.Row="6"
Style="{StaticResource ChartToggleButton}"
IsChecked="{Binding AnnotationCreationVM.FibRetr}"
CommandParameter="{x:Type dt:FibonacciRetracementAnnotationViewModel}"/>
ParentView view model,
public ICommand AnnotationCreatedCommand => new ActionCommand<AnnotationCreationMVVMArgs>(e =>
{
try
{
var annotation = e.NewAnnotationViewModel;
if (annotation != null)
{
if (annotation is ITradingAnnotationViewModel tradingAnnotation)
{
((AnnotationBase)tradingAnnotation.Annotation).Selected += OnAnnotationSelectionChanged;
((AnnotationBase)tradingAnnotation.Annotation).Unselected += OnAnnotationSelectionChanged;
}
annotation.IsEditable = true;
annotation.CanEditText = true;
annotation.IsSelected = true;
FibRetr = false;
FibExt = false;
Hns = false;
Xabcd = false;
PitchFork = false;
EllioteWave = false;
Line = false;
}
IsAnnotationCreationEnable = false;
IsAnnotationDrawn = false;
OnPropertyChanged("IsAnnotationDrawn");
}
catch { }
});
private void OnAnnotationSelectionChanged(object sender, EventArgs eventArgs)
{
try
{
var parent = ((System.Windows.FrameworkElement)((System.Windows.FrameworkElement)sender).Parent).TemplatedParent;
if(parent is SciChartSurface)
{
var surface = parent as SciChartSurface;
if(null != surface)
{
OHLCVChart chart = surface.DataContext as OHLCVChart;
Annotations = chart.LAnnotations;
SelectedAnnotation = Annotations.FirstOrDefault(x => x.IsSelected);
}
}
}
catch { }
}
If there is any other way to club all Trading related annotations + TextBox, Line, TrendLine Annotations creation dynamically using any other modiefier, that will do. We are tying to build Trading charts: with Ability to add annotations.
Thanks.
- Roger Thomas asked 3 years ago
- You must login to post comments
Hi Roger,
Thanks for your inquiry.
I have logged this in our tracking system. We’ll investigate this possibility and will get back to you as soon as we have an update.
With best regards,
Oleksandr
- Oleksandr Shvets answered 3 years ago
- You must login to post comments
Please login first to submit.