我想根据Ramin给我的提示回答我自己的问题。
我深入研究了源代码,发现有一个
TrackerFormatString
我可以更改:
<oxy:LineSeries TrackerFormatString="{}{0}
{1}: {2:0.0}
{3}: {4:0.0}"/>
请注意我代码中的


,即如何在 XAML 中输入换行符。
另请注意开头的
{}
,这是 XAML 中的转义字符。
如果在 C# 中,则只是:
{0}\n{1}: {2:0.0}\n{3}: {4:0.0}
您应该设置
DefaultTrackerTemplate
。这是一个向您展示方法的小例子:
<Grid>
<oxy:Plot Title="AAA">
<oxy:Plot.Axes>
<oxy:LinearAxis Position="Left" Title="Left: " />
<oxy:LinearAxis Position="Bottom" Title="Bottom: " />
</oxy:Plot.Axes>
<oxy:Plot.Series>
<oxy:LineSeries x:Name="ls" ItemsSource="{Binding Points}"/>
</oxy:Plot.Series>
<oxy:Plot.DefaultTrackerTemplate>
<ControlTemplate>
<oxy:TrackerControl Position="{Binding Position}"
BorderThickness="1">
<oxy:TrackerControl.Content>
<StackPanel >
<DockPanel>
<TextBlock Text="{Binding XAxis.Title}" Foreground="Red" />
<TextBlock DockPanel.Dock="Right" Text="{Binding DataPoint.X}" Foreground="Red" />
</DockPanel>
<DockPanel>
<TextBlock Text="{Binding YAxis.Title}" Foreground="Green" />
<TextBlock DockPanel.Dock="Right" Text="{Binding DataPoint.Y}" Foreground="Green"
FontWeight="Bold" />
</DockPanel>
</StackPanel>
</oxy:TrackerControl.Content>
</oxy:TrackerControl>
</ControlTemplate>
</oxy:Plot.DefaultTrackerTemplate>
</oxy:Plot>
</Grid>
希望有帮助。
private PlotModel CreatePlotModel(字符串标题, OxyColor 颜色) { varplotModel = new PlotModel { };
// Data series
var series = new LineSeries
{
Title = title,
TrackerFormatString = "{0}\nTime: {2:0.000}\nValue: {4:0.000}",
Color = color
};
plotModel.Series.Add(series);
plotModel.Legends.Add(new OxyPlot.Legends.Legend
{
LegendPosition = OxyPlot.Legends.LegendPosition.TopCenter,
LegendTextColor = color
});
return plotModel;
}