Reputation: 4591
<s:FastLineRenderableSeries.PointMarker>
<s:SpritePointMarker PointMarkerTemplate="{StaticResource AnyWpfControlTemplateCanGoHere}"/>
Based on the user selection from many options, I need to set this template at runtime. The template is already been defined in generic dictionary which is like this
<ControlTemplate x:Key="RightTriangleAnnotations">
<Polygon Points="0 0, 20 20,0 20" x:Name="poly" Fill="Green" Stroke="Red"></Polygon>
My code is something like this
var pointMarker = new SpritePointMarker();
pointMarker.Template = **Here the template should go**
renderSeries.PointMarker = pointMarker;
Any idea how could I set the template at runtime.
Upvotes: 1
Views: 1093
Reputation: 1665
Basicaly, that depends on where your resources are defined. You just need to get the template from the dictionary. For example if your dictionary is defined for an application:
Application.Current.Resources["RightTriangleAnnotations"] as ControlTemplate
Or you can use any visual object such as SpritePointMarker::Resources if dictionary is directly attached to it in XAML. Please refer to this question for detailed solution: How can I access ResourceDictionary in wpf from C# code?
OR if you haven't specified your dictionary in any XAML file you have to load dictionary first and then assign it to a visual object to be able to get the desired resource by key. Check this question for detailed info: Access ResourceDictionary items programmatically
Upvotes: 1