首页 > 解决方案 > Xamarin Forms WPF项目中的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>

标签: oxyplot

解决方案


您可以通过修改控制模板来更改 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>

当然,您也可以在上面设置绑定,但为了举例,在上面的示例中直接给出颜色。


推荐阅读