我在 WPF 中使用LiveCharts
堆积柱形图。图表位于Tabview
绑定的ViewModels
中。加载应用程序后,图表将显示DataLabel
,但是在TabViews
之间切换时它们会消失。
为什么DataLabels消失了?
型号:
public ChartValues<double> ChartValuesDone { get; set; }
public ChartValues<double> ChartValuesInProgress { get; set; }
public Func<double, string> Formatter { get; set; }
图表:
<lvC:CartesianChart Zoom="X"
LegendLocation="Top"
FontSize="20"
Margin="15">
<lvC:CartesianChart.Series>
<lvC:StackedColumnSeries StackMode="Values"
Values="{Binding ChartValueDone}"
DataLabels="True" Title="Done" />
<lvC:StackedColumnSeries Fill="Gray"
StackMode="Values"
Values="{Binding ChartValuesInProgress}"
DataLabels="True" Title="In Progress" />
</lvC:CartesianChart.Series>
<lvC:CartesianChart.AxisX >
<lvC:Axis Labels="{Binding Labels}"
FontSize="16"
LabelsRotation="-15"
Foreground="Black"
Separator="{x:Static lvC:DefaultAxes.CleanSeparator}"
/>
</lvC:CartesianChart.AxisX>
<lvC:CartesianChart.AxisY >
<lvC:Axis MinValue="0" FontSize="16" LabelFormatter="{Binding Formatter}" Foreground="Black" Margin="10,0,0,0"/>
</lvC:CartesianChart.AxisY>
</lvC:CartesianChart>
TabView:
<TabControl ItemsSource="{Binding Charts}" SelectedIndex="0">
<TabControl.Resources>
<DataTemplate DataType="{x:Type model:ChartModel }">
<charts:Chart />
</DataTemplate>
</TabControl.Resources>
<TabControl.ItemContainerStyle>
<Style TargetType="TabItem" BasedOn="{StaticResource CoDeTabItem}" >
<Setter Property="Header" Value="{Binding Name}" />
</Style>
</TabControl.ItemContainerStyle>
</TabControl>
感谢您的帮助!