Styling WPF OxyPlot PlotViews in XAML

When customizing the plot view of OxyPlot, you can either explicitly define the plot through various controls, or customize it through binding to PlotModel

.

So in the first case, the XAML for a graph of two objects LineSeries

might look something like

<oxy:Plot Title="Some plot">
    <oxy:Plot.Axes>
        <oxy:LinearAxis Position="Left" />
        <oxy:LinearAxis Position="Bottom" />
    </oxy:Plot.Axes>
    <oxy:Plot.Series>
        <oxy:LineSeries ItemsSource="{Binding ActualSeriesData1}" DataFieldX="X" DataFieldY="Y"/>
        <oxy:LineSeries ItemsSource="{Binding ActualSeriesData2}" DataFieldX="X" DataFieldY="Y"/>
    </oxy:Plot.Series>
</oxy:Plot>

      

with a very thin view model. On the other hand, in the second case, I would just have something like

<oxy:PlotView Model="{Binding SomePlotModel}" />

      

and plot the actual graph in the view model. There are pros and cons for both settings, but I find the first approach usually works better when I know in advance what I actually want to build, whereas the second approach allows the content of the plot to be dynamically changed.

My problem is this: for the first case, I know how to add a common style for all graphs. If, for example, I want them to make them look like the sea, I would just add something like

<x:Array Type="Color" x:Key="SeabornColors">
    <Color>#4c72b0</Color>
    <Color>#55a868</Color>
    <Color>#c44e52</Color>
    <Color>#8172b2</Color>
    <Color>#ccb974</Color>
    <Color>#64b5cd</Color>
</x:Array>
<Style TargetType="oxy:Plot">
    <Setter Property="PlotAreaBackground" Value="#EBEBF2" />
    <Setter Property="PlotAreaBorderThickness" Value="0" />
    <Setter Property="TitleFont" Value="Segoe UI" />
    <Setter Property="TitleFontWeight" Value="Normal" />
    <Setter Property="DefaultColors" Value="{StaticResource SeabornColors}"/>
</Style>
<Style TargetType="oxy:LinearAxis">
    <Setter Property="TicklineColor" Value="White" />
    <Setter Property="MajorGridlineColor" Value="White" />
    <Setter Property="MinorGridlineColor" Value="White" />
    <Setter Property="ExtraGridlineColor" Value="White" />
    <Setter Property="AxislineColor" Value="White" />
    <Setter Property="TitleColor" Value="Black" />
    <Setter Property="TextColor" Value="Black" />
    <Setter Property="Font" Value="Segoe UI" />
    <Setter Property="TitleFont" Value="Segoe UI" />
    <Setter Property="TickStyle" Value="None" />
    <Setter Property="MajorGridlineStyle" Value="Solid" />
</Style>

      

to my ResourceDictionary

. How can I achieve the same effect in the second case i.e. Using oxy:PlotView

? I can set some general styling properties with <Style TargetType="oxy:PlotView" />

, but how would I style, say, everything LineSeries

contained Series

within Model

within PlotView

?

+3


source to share





All Articles