请问我怎么通过后台编程来获取Name为ChartArea这个Grid,通过VisualTreeHelper.GetChildrenCount(Charts)返回值为“0”,请问为什么不是1?谢谢!
代码如下:
<UserControl x:Class="PlotLine.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:charting="clr-namespace:Microsoft.Windows.Controls.DataVisualization.Charting;assembly=Microsoft.Windows.Controls.DataVisualization"
xmlns:datavis="clr-namespace:Microsoft.Windows.Controls.DataVisualization;assembly=Microsoft.Windows.Controls.DataVisualization">
<UserControl.Resources>
<!-- styles -->
<Style x:Key="PlotAreaStyle" TargetType="Grid">
<Setter Property="Background" Value="White"/>
</Style>
<Style x:Key="GridLineStyle" TargetType="Line">
<Setter Property="Stroke" Value="LightGray"/>
</Style>
</UserControl.Resources>
<charting:Chart Name="Charts" Width="auto" Height="auto" PlotAreaStyle="{StaticResource PlotAreaStyle}">
<charting:Chart.Template>
<ControlTemplate TargetType="charting:Chart" x:Name="ChartTemplate" >
<Grid x:Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}" >
<Grid Name="PlotArea" Style="{TemplateBinding PlotAreaStyle}">
<Grid x:Name="GridLinesContainer" />
<Path Fill="#FFFFFFFF" Stretch="UniformToFill" Stroke="#FF000000" Data="M36,32 C44.465485,13.278256 46.24641,0.49792495 80,20"/>
</Grid>
</Grid>
</ControlTemplate>
</charting:Chart.Template>
<charting:Chart.Axes>
<charting:LinearAxis Orientation="Vertical" ShowGridLines="True" Title="Y轴"
GridLineStyle="{StaticResource GridLineStyle}" />
<charting:LinearAxis Orientation="Horizontal" ShowGridLines="True" Title="X轴" Maximum="100" Minimum="0"
GridLineStyle="{StaticResource GridLineStyle}" />
</charting:Chart.Axes>
</charting:Chart>
</UserControl>