I managed to be able to render the EllipsePointMarkers, but here is the thing: It only works when I declare the PointMarker in my view model inside the constructor of the XyScatterRenderableSeriesViewModel. The Style with the PointerMarkerTemplate is NOT APPLIED for some reason. Could this be a bug? Please note that in the following code in the view model I specify the color to be “Red” (ARGB(255, 255, 0, 0) but in xaml the template specifies yellow for the fill and stroke.
I absolutely need the PointMarker Template to work because I want to be able to change the color and thickness of the Scatter points during runtime via UI (function in my custom legend).
The following are code snippets from my view model and the corresponding xaml:
ChartSeries.Add(new XyScatterRenderableSeriesViewModel()
{
DataSeries = dataSeries,
//Stroke = color,
//StrokeThickness = 10,
IsVisible = isVisible,
AntiAliasing = useAntiAliasing,
IsSelected = isSelected,
XAxisId = "DateTimeAxis",
YAxisId = yAxisId,
PointMarker = new EllipsePointMarker()
{
Fill = Color.FromArgb(255, 255, 0, 0),
Stroke = Color.FromArgb(255, 255, 0, 0),
StrokeThickness = 5
}
});
<UserControl.Resources>
<Style TargetType="{x:Type s:XyScatterRenderableSeries}">
<Setter Property="PointMarkerTemplate">
<Setter.Value>
<ControlTemplate>
<s:EllipsePointMarker Fill="Yellow" Stroke="Yellow" StrokeThickness="15"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<s:EffectConverter x:Key="EffectConverter"/>
<DropShadowEffect x:Key="LegendDropShadow" BlurRadius="10" Direction="-45" ShadowDepth="5" Color="Black"/>
<SolidColorBrush x:Key="LegendTextBrush" Color="#5F5F5F"/>
<resources:VisibilityToBooleanConverter x:Key="VisibilityToBooleanConverter"/>
<resources:CustomCategoryDateTimeAxisLabelProvider x:Key="LabelProvider"/>
</UserControl.Resources>
- bbmat asked 6 years ago
- You must login to post comments
There is a little known quirk in WPF called DependencyProperty Value Precedence. If any property is set in code, then the same property cannot be set by a style or a template, as the property set in code takes precedence over the style or template value.
PointMarkerTemplate is where we apply a template to a RenderableSeries
PointMarker is where we apply a PointMarker in code.
As a result, if you have set the PointMarker on a series, then the PointMarkerTemplate will no longer have an effect.
Workarounds:
1/ Use only PointMarker for both setting in style and setting in code. If you set a PointMarker in a style, make sure that you use x:Shared = false on the style
<s:XyScatterRenderableSeries>
<s:XyScatterRenderableSeries.Style>
<Style TargetType="s:XyScatterRenderableSeries" x:Shared="False">
<Setter Property="PointMarker">
<Setter.Value>
<EllipsePointMarker Width="5" Height="5"/>
</Setter.Value>
</Setter>
</Style>
</s:XyScatterRenderableSeries.Style>
</s:XyScatterRenderableSeries>
2/ Use only PointMarkerTemplate for setting the initial value of the pointmarker and your style-set value.
This workaround is more complicated as it requires creating a style or template in code, or use of WPF Data-triggers.
Let me know if this helps,
Best regards,
Andrew
- Andrew Burnett-Thompson answered 6 years ago
- You must login to post comments
Hi Andrew,
The above suggestions did not work for me, the EllipsePointMarkers did not change any of their properties as function of the style.
But Yuriy suggested setting a StyleKey in my view model and on the Style in xaml and that did the trick.
- bbmat answered 6 years ago
- last edited 6 years ago
- Ah super! Glad its resolved :)
- You must login to post comments
Please login first to submit.