WPF style in Application resources

396 views Asked by At

I have a style in application resources which I want to apply to many different pie charts. The style looks like this:

<Style x:Key="aaa" TargetType="{x:Type nm:CustomChartControl}">
  <Setter Property="..." Value="..." />
  <!-- etc -->
  <nm:CustomChartControl.Series>
  <nm:PieSeries /> <!-- PROBLEM -->
  </nm:CustomChartControl.Series>
</Style>

There is a lot more properties which I exluded for simplicity. This all works well. Now, some of my pies need to have a different "model" for paitning background for a slice (ex dashed), and this is were the problem occurs.

When I set a model (at runtime) for nm:PieSeries in a particular chart, then this model is also applied to all other pies that are shown in application. As if there is only one instance of that is used by all pies that applied the style.

Is there some way I can tell it to create a new instance of nm:PieSeries each time a Style is applied to new control?

1

There are 1 answers

0
15ee8f99-57ff-4f92-890c-b56153 On BEST ANSWER

You might try creating the PieSeries as a separate, non-shared resource:

<nm:PieSeries x:Shared="False" x:Key="NonSharedPieSeries" />

And then use that resource in the style:

Value="{Binding Source={StaticResource NonSharedPieSeries}}" 

(...and thanks OP for correcting my error in how to bind it to Value).