Hi All,
Im trying to kind of reproduce trademarkers example, but i cant get the datacontext of Annotation bound to show the tooltip data.
this is the way im doing things:
first i let the user select an area to place a box annotation via SimpleSelectionModifier
View XAML
s:SciChartSurface x:Name="_chart" Annotations="{s:AnnotationsBinding Annotations}"
<!-- axis not showed for legibility !--
s:SciChartSurface.ChartModifier
s:ModifierGroup
mods:SimpleSelectionModifier IsEnabled="{Binding EnableAnnotation}"
i:Interaction.Triggers
i:EventTrigger EventName="RangeSelected"
SourceObject="{Binding RelativeSource={RelativeSource AncestorType={x:Type
mods:SimpleSelectionModifier }}}"
prism:InvokeCommandAction Command="{Binding RangeSelectedEvent}" TriggerParameterPath="Coordinates"/
/i:EventTrigger
/i:Interaction.Triggers
/mods:SimpleDataPointSelectionModifier
/s:ModifierGroup
/s:SciChartSurface.ChartModifier
/s:SciChartSurface
On the VieModel side i’ve got this property to save CustomAnnotationViewmodels , bound to the scichart.Annotations property
private ObservableCollection<IAnnotationViewModel _annotations = new ObservableCollection<IAnnotationViewModel>();
public ObservableCollection<IAnnotationViewModel> Annotations
{
get { return _annotations; }
set { SetProperty(ref _annotations, value); }
}
and this Command executed on the rangeSelectedEvent when i create the annotation on the coordinates selected by the user viewmodel and add some custom ddata
void ExecuteRangeSelectedEvent(Coordinates parameter)
{
var annotation = new CustomAnnotationViewModel
{
IsEditable = true,
CanEditText = true,
X1 = parameter.X1,
X2 = parameter.X2,
Y1 = parameter.Y1,
Y2 = parameter.Y2,
Data = new Data("test", "text tooltip", DataType.CoolData)
};
Annotations.Add(annotation);
EnableAnnotation = false;
}
The CustomAnnotationViewModel is based on the BuyMarkerAnnotationViewModel of the tradeMarkers Example.
and interface to support Data management and CustomAnnottionVIewModel that implementado the interface
public interface ISupportData : IAnnotationViewModel
{
Data Data { get; set; }
}
public class CustomAnnotationViewModel : CompositeAnnotationViewModel, ISupportData
{
private Wave _data;
public Wave Data
{
get { return _data; }
set
{
_data = value;
OnPropertyChanged("Data");
}
}
public override Type ViewType
{
get { return typeof(CustomAnnotation); }
}
}
and finally de XAML on CustomAnnotation where everything should be bound
s:CompositeAnnotation x:Class="CustomAnnotation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="http://schemas.abtsoftware.co.uk/scichart"
X1="{Binding X1, Mode=TwoWay}"
Y1="{Binding Y1, Mode=TwoWay}"
X2="{Binding X2, Mode=TwoWay}"
Y2="{Binding Y2, Mode=TwoWay}"
AnnotationCanvas="BelowChart"
IsEditable="true"
s:CompositeAnnotation.Annotations
s:BoxAnnotation Background="Coral"
CoordinateMode="Relative"
Opacity="0.3"
X1="0"
X2="1"
Y1="0"
Y2="1" /
s:LineArrowAnnotation CoordinateMode="Relative"
Stroke="Coral"
StrokeDashArray="2,4"
StrokeThickness="1"
X1="0"
X2="1"
Y1="0.5"
Y2="0.5" /
s:LineArrowAnnotation CoordinateMode="Relative"
Stroke="Coral"
StrokeDashArray="2,4"
StrokeThickness="1"
X1="0.5"
X2="0.5"
Y1="0"
Y2="1" /
s:TextAnnotation x:Name="MeasureText"
Background="CornflowerBlue"
CoordinateMode="Relative"
CornerRadius="3"
Foreground="White"
HorizontalAnchorPoint="Center"
X1="0.5"
Y1="1"
ToolTipService.ToolTip
ToolTip Foreground="#222"
Grid Margin="6" DataContext="{**Binding Data**}"
Grid.RowDefinitions
RowDefinition Height="Auto" /
RowDefinition Height="Auto" /
/Grid.RowDefinitions
Grid.ColumnDefinitions
ColumnDefinition Width="Auto" /
ColumnDefinition Width="Auto" /
ColumnDefinition Width="Auto" /
/Grid.ColumnDefinitions
TextBlock Grid.Row="0" Grid.Column="0" Text="Type: " /
TextBlock Grid.Row="1" Grid.Column="0" Text="Text: " /
TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Type}" Foreground="#FF00B400"/
TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding LabelText}" /
/Grid
/ToolTip
/ToolTipService.ToolTip
/s:TextAnnotation
/s:CompositeAnnotation.Annotations
/s:CompositeAnnotation
I dont mind if everything is shown on tooltip or other way. but when oi run it a get this binding error.
Data is not found on ViewModel
Any ideas? Can anybody see where im making a mistake?
any help would be very appreciated.
thanks
- silla ruedas asked 2 years ago
- last active 2 years ago