Xamarin Forms WPF项目中的OxyPlot,如何更改跟踪器文本颜色

时间:2019-02-01 15:46:01

标签: oxyplot

我正在Xamarin Forms项目中使用OxyPlot。

在WPF中,跟踪器(当我单击数据点时会弹出)具有白色背景和黄色文本,因此无法看到。

但是在UWP中,黄色背景和黑色文字就可以了。

如何将跟踪器的字体颜色更改为黑色?

xmlns:oxy="clr-namespace:OxyPlot.Xamarin.Forms;assembly=OxyPlot.Xamarin.Forms"
<oxy:PlotView Model="{Binding MyModel}"
              HorizontalOptions="FillAndExpand"
              VerticalOptions="FillAndExpand">
</oxy:PlotView>

1 个答案:

答案 0 :(得分:0)

您可以通过修改控制模板来更改Oxyplot Tracker的默认颜色。例如,

 <oxy:PlotView Height="500" Width="500" Model="{Binding MyModel}">
            <oxy:PlotView.DefaultTrackerTemplate>
                <ControlTemplate>
                    <oxy:TrackerControl Position="{Binding Position}" LineExtents="{Binding PlotModel.PlotArea}">
                        <oxy:TrackerControl.Background>
                            <SolidColorBrush Color="LightBlue" />
                        </oxy:TrackerControl.Background>
                        <oxy:TrackerControl.Content>
                            <TextBlock Text="{Binding}" Margin="7" Foreground="Black" />
                        </oxy:TrackerControl.Content>
                    </oxy:TrackerControl>
                </ControlTemplate>
            </oxy:PlotView.DefaultTrackerTemplate>
        </oxy:PlotView>

当然,可以设置以及在上述的结合,但出于举例的目的,给定的颜色直接在上面的示例。