我正在尝试在代码隐藏中设置linearAxis Title属性,但它没有显示,有人可能会告诉我,如果我做错了吗?
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" Background="White">
<chart:Chart x:Name="BarChart" Foreground="Gray" Title="Midwest City Populations">
<chart:BarSeries
Title="Population" IndependentValueBinding="{Binding Name}"
DependentValueBinding="{Binding Population}"
>
<chart:BarSeries.DataPointStyle>
<Style TargetType="chart:BarDataPoint" x:Name="stylename">
<Setter Property="Background" Value="Purple" x:Name="test" />
</Style>
</chart:BarSeries.DataPointStyle>
</chart:BarSeries>
<chart:Chart.Axes>
<chart:CategoryAxis Title="City" Orientation="Y" FontStyle="Italic"/>
<chart:LinearAxis x:Name="axis_for_bargraph"
Orientation="X"
Minimum="10"
Maximum="500"
Title="kaas"
ShowGridLines="True" FontStyle="Italic"/>
</chart:Chart.Axes>
</chart:Chart>
axis_for_bargraph = new LinearAxis();
axis_for_bargraph.Title = "MB USed";
答案 0 :(得分:1)
通过axis_for_bargraph = new LinearAxis();
,您将创建一个新的inctance并将其赋予标题,而不是UI中显示的实例。
如果这会导致访问权限,则需要以其他方式访问它。也许这会奏效:
Axis axis = BarChart.Axes.FindOrDefault(a => a.Name == "axis_for_bargraph");
if (axis != null)
axis.Title = "MB Used";
但我认为通过绑定解决这个问题会更容易。只需绑定一个属性,即。 LinearAxisTitle
,指向LinearAxis的标题并更改此属性。