<s:SciChartGroup Grid.Row="1" Name="charts"
ItemsSource="{Binding ChartPaneViewModels}"
s:ThemeManager.Theme="{Binding ElementName=ThemeCombo, Path=SelectedItem}"
ItemContainerStyle="{StaticResource ChartPaneStyle}">
<s:SciChartGroup.ItemTemplate>
<DataTemplate x:Name="template">
<s:SciStockChart Padding="0"
BorderThickness="0,0,1,1" *** Annotations="{Binding TradeAnnotations}"<--How to binding this to first chart? ***
IsXAxisVisible="{Binding IsFirstChartPane}"
IsPanEnabled="{Binding ParentViewModel.IsPanEnabled}"
IsRubberBandZoomEnabled="{Binding ParentViewModel.IsZoomEnabled}"
VerticalChartGroupId="{Binding ParentViewModel.VerticalChartGroupId}"
ViewportManager="{Binding ParentViewModel.ViewportManager}" IsRolloverEnabled="True"
SeriesSource="{Binding ChartSeriesViewModels}">
<s:SciStockChart.XAxis>
<s:CategoryDateTimeAxis Name="xAxis"
TextFormatting="MM-dd HH:mm:ss"
VisibleRange="{Binding ParentViewModel.XVisibleRange, Mode=TwoWay}"
DrawMajorBands="False"
DrawMinorGridLines="True"
GrowBy="0,0.05"/>
</s:SciStockChart.XAxis>
<s:SciStockChart.XAxisStyle>
<Style TargetType="s:CategoryDateTimeAxis">
<Setter Property="DrawMajorBands" Value="True"/>
<Setter Property="DrawMinorGridLines" Value="False"/>
<Setter Property="VisibleRange" Value="{Binding ParentViewModel.XVisibleRange, Mode=TwoWay}"/>
<Setter Property="GrowBy" Value="0, 0.05"/>
</Style>
</s:SciStockChart.XAxisStyle>
<s:SciStockChart.YAxes>
<s:NumericAxis AutoRange="Always"
Id="Y2"/>
</s:SciStockChart.YAxes>
<s:SciStockChart.YAxisStyle>
<Style TargetType="s:NumericAxis">
<Setter Property="AutoRange" Value="Always"></Setter>
<Setter Property="TextFormatting" Value="{Binding YAxisTextFormatting}"/>
<Setter Property="MinorsPerMajor" Value="{Binding IsFirstChartPane, Converter={StaticResource MinorsPerMajorConverter}}"/>
<Setter Property="MaxAutoTicks" Value="{Binding IsFirstChartPane, Converter={StaticResource MaxAutoTicksConverter}}"/>
<Setter Property="GrowBy" Value="{Binding IsFirstChartPane, Converter={StaticResource GrowByConverter}}"/>
</Style>
</s:SciStockChart.YAxisStyle>
</s:SciStockChart>
</DataTemplate>
</s:SciChartGroup.ItemTemplate>
</s:SciChartGroup>
- Hwa Fun asked 9 years ago
- You must login to post comments
Hi Hwa,
You have a collection of ChartPaneViewModels right?
Then you can expose an AnnotationCollection on a chart pane viewmodel, e.g.
public class ChartPaneViewModel
{
private AnnotationCollection _annotationCollection = new AnnotationCollection();
public ChartPaneViewModel()
{
// Then only for first ChartPaneViewModel add one annotation
_annotationCollection.Add(new TextAnnotation() { Text="Hello!", X1=0, Y1=100};
}
public AnnotationCollection { get { return _annotationCollection; } }
}
Then you can bind to it in the View like this
<s:SciChartGroup
... >
<s:SciChartGroup.ItemTemplate>
<DataTemplate x:Name="template">
<s:SciStockChart Padding="0"
...
Annotations="{Binding AnnotationCollection}>
...
</s:SciStockChart>
</DataTemplate>
<s:SciChartGroup.ItemTemplate>
</s:SciChartGroup>
If you want to extend this to be more MVVM friendly, please see this article: Editing annotations and keeping track of them in an mvvm application
Best regards,
Andrew
- Andrew Burnett-Thompson answered 9 years ago
- You must login to post comments
Hi Andrew
Thanks for your reply .
public class AbtChartControl_ViewModel : BaseViewModel
{
public AbChartControl_ViewModel(Strategy s)
{
s.AddTradeFlagHandler += AddAnnotation;
_annotations = new AnnotationCollection();
_chartPaneViewModels.Add(new OhlcPaneViewModel(this, s) { IsFirstChartPane = true });
_chartPaneViewModels.Add(new VolumePaneViewModel(this, s);
}
private void AddAnnotation(TradeFlagEventArgs e)
{
IAnnotation annotation;
if (e.Direction == EDirection.Buy)
annotation = new BuyMarkerAnnotation() { X1 = e.Datetime, Y1 = e.Price, };
else
annotation = new SellMarkerAnnotation() { X1 = e.Datetime, Y1 = e.Price };
this._annotations.Add(annotation);
}
private AnnotationCollection _annotations;
public AnnotationCollection TradeAnnotations
{
get { return _annotations; }
set
{
_annotations = value;
RaisePropertyChanged("TradeAnnotations");
}
}
}
Then I bind to View as you , run it , An exception occurs :
System.NullReferenceException
- Hwa Fun answered 9 years ago
- last edited 9 years ago
- You must login to post comments
On not ItemTemplate, Running normally , But I do not know much about modifier , I don’t know set
Pan, Zoom , VisibleRange , etc.
- Hwa Fun answered 9 years ago
- last edited 9 years ago
-
to replace a version is no problem
- You must login to post comments
Please login first to submit.