0

我正在尝试在代码隐藏中设置一个 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";
4

1 回答 1

1

通过axis_for_bargraph = new LinearAxis();您创建一个新实例并为其指定标题,而不是 UI 中显示的实例。

如果这导致访问冲突,您需要以另一种方式访问​​它。也许这会起作用:

Axis axis = BarChart.Axes.FindOrDefault(a => a.Name == "axis_for_bargraph");
if (axis != null)
    axis.Title = "MB Used";

但我认为通过绑定解决这个问题要容易得多。只需将属性 fe 绑定LinearAxisTitle到 LinearAxis 的标题并更改此属性。

于 2013-09-13T09:53:11.993 回答