1
 <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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.