Nicros
Nicros

Reputation: 5203

Modifying visual states in blend?

I'm playing around with a 3rd party package for charting (Modern UI Charts). It looks great and seems to work for what I need.

But in the example code that comes with the package, all of the styles and templates are in a resource dictionary in Generic.xaml, as they are all custom (lookless) controls.

But I want to override a lot of what's in that Generic.xaml file, including some visual states. Specifically, in the chart I want to use, it animates out and then in when any of the data changes. I want to turn that off.

If I try to edit the templates or styles in blend, I see some of the code from the default xaml, but not the visual states. Is there a way to modify those?

Or how can I completely override the Generic.xaml and replace it with my own?

Upvotes: 0

Views: 128

Answers (1)

pushpraj
pushpraj

Reputation: 13679

it is easy to override when you are inheriting the control and creating your own by DefaultStyleKeyProperty.OverrideMetadata

I am not sure about your implementation. typically if you create a style for the concerned type it overrides the existing unless you use BasedOn Attribute.

example

<Style TargetType="local:PieChart" BasedOn="{StaticResource BaseChartStyle}">
    <Setter Property="ChartAreaStyle" Value="{StaticResource PieChartChartAreaStyle}" />
    <Setter Property="PlotterAreaStyle" Value="{StaticResource PieChartPlotterAreaStyle}" />
</Style>

if you redfine above as

<Style TargetType="local:PieChart" >
    ... your style
</Style>

it will override the existing style

or you can choose to override specific property by deriving from existing style for the element by BasedOn="{StaticResource {x:Type local:PieChart}}"

<Style TargetType="local:PieChart" BasedOn="{StaticResource {x:Type local:PieChart}}">
    <Setter Property="ChartAreaStyle" Value="{StaticResource MyChartAreaStyle}" />
</Style>

In similar way you can override Template property of your desired element with your own version.

Upvotes: 1

Related Questions