C# 为codebehind中的图表设置标题属性不起作用?
我试图在codebehind中设置linearAxis标题属性,但它没有显示,有人可能会告诉我我是否做错了什么C# 为codebehind中的图表设置标题属性不起作用?,c#,xaml,charts,C#,Xaml,Charts,我试图在codebehind中设置linearAxis标题属性,但它没有显示,有人可能会告诉我我是否做错了什么 <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">
<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";
_条形图的_轴=新的线性轴();
轴用于条形图。Title=“MB已使用”;
通过轴,用于条形图=新的线性轴()代码>您正在创建一个新实例并为其指定标题,而不是UI中显示的实例
如果这导致访问冲突,您需要以另一种方式访问它。也许这会奏效:
Axis axis = BarChart.Axes.FindOrDefault(a => a.Name == "axis_for_bargraph");
if (axis != null)
axis.Title = "MB Used";
但我认为用绑定解决这个问题更容易。只需将属性f.e.LinearAxisTitle
绑定到您的LinearAxis的标题,然后更改此属性。为我提供了访问权限我没有findOrDefault方法我想这是有意义的,thanx