Styling the plot

Oystein Bjorke 10 років тому 0
This discussion was imported from CodePlex

Tech_Junkie wrote at 2012-07-19 13:19:

I am busy implementing a lineseries with two axes to show an overview of frequencies and their intensity. And until now I've used the styling as I've copied it from an example, in the definition of a lineseries:

LineSeries ls = new LineSeries()
{
    Color = OxyColors.Green,
    StrokeThickness = 2,
    MarkerType = MarkerType.Square,
    MarkerSize = 3,
    MarkerStroke = OxyColors.Black,
    MarkerStrokeThickness = 1
};
I was wondering if (and how) I can take these styling elements out of the code and put it in a styling in a xaml ResourceDictionary? Is this possible?


Tech_Junkie wrote at 2012-07-20 09:38:

I seem to have already solved this by using a vertical LineAnnotation :)

Thank you for providing the functionality!


Tech_Junkie wrote at 2012-07-20 14:03:

An additional question though, is it possible to have a vertical line and a horizontal text-label with it? Or do I have to position a TextAnnotation myself? (which is tricky, because the scaling depends on zooming, and I want a constant distance between the line and the text)


objo wrote at 2012-08-08 23:56:

Yes, the line annotation should have a 'Text' property you could use.You have some control of the position/alignment - see the TextPosition, TextMargin, TextHorizontalAlignment and TextVerticalAlignment properties.


Tech_Junkie wrote at 2012-08-09 09:18:

This is true, but if I render a vertical line, the text will also be vertical and I cannot find how to change this to a horizontal text with my vertical line. Is this possible?

I currently 'solve' this by adding a textannotation below the vertical line and leaving a space at the bottom of the line by giving it a minimumY


objo wrote at 2012-08-10 13:10:

Added a TextOrientation property in the LineAnnotation class.


Tech_Junkie wrote at 2012-08-10 13:31:

Thank you for the quick fix!


Tech_Junkie wrote at 2012-08-13 12:34:

Tech_Junkie wrote:

I am busy implementing a lineseries with two axes to show an overview of frequencies and their intensity. And until now I've used the styling as I've copied it from an example, in the definition of a lineseries:

LineSeries ls = new LineSeries()
{
    Color = OxyColors.Green,
    StrokeThickness = 2,
    MarkerType = MarkerType.Square,
    MarkerSize = 3,
    MarkerStroke = OxyColors.Black,
    MarkerStrokeThickness = 1
};
I was wondering if (and how) I can take these styling elements out of the code and put it in a styling in a xaml ResourceDictionary? Is this possible?

I see now that my second post apparently did not cover my complete question. Objo, would it be possible to do styling of elements in a plot out of the code, and in xaml?


objo wrote at 2012-08-23 15:59:

If you define your plot in XAML (WPF/SL) it should be possible to use a Style from a ResourceDictionary on the OxyPlot.Wpf.LineSeries. I have no example on this, but believe it should work. Let us know if there is a bug!


aec wrote at 2012-08-23 21:23:

Hi, I have already done this with WPF and it works fine!


aec wrote at 2012-08-23 21:24:

This discussion leads me to an additional question: Is it possible to define a line series (or in my case a plot model) with C# and to change the style afterwards with WPF xaml code? This way, we have a default style defined by the C# code, which can be overwritten later on. This yields more flexibility.


objo wrote at 2012-08-24 08:33:

You could override property metadata

http://msdn.microsoft.com/en-us/library/ms754209.aspx

but I don't think it is possible to mix a PlotModel and a Plot defined by XAML...


aec wrote at 2012-08-24 11:04:

Hi objo, I know this. Okay, it was just an idea but this realization leads to too much effort for me. In addition, I like brief and neat program code.