How can I get the property of ControlTemplate element?
My XAML looks like this:
<charting:Chart
Name="pieSeries1">
<charting:PieSeries
IndependentValuePath="Category" DependentValuePath="Amount"
Palette="{StaticResource MyPalette}">
</charting:PieSeries>
<charting:Chart.T开发者_运维问答emplate>
<ControlTemplate TargetType="charting:Chart">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<datavis:Title Content="{TemplateBinding Title}" Style="{TemplateBinding TitleStyle}" Margin="1"/>
<Grid Grid.Row="1" Margin="5,0,5,0">
<chartingPrmtvs:EdgePanel x:Name="ChartArea" MinHeight="200" Style="{TemplateBinding ChartAreaStyle}">
<Grid Canvas.ZIndex="-1" Style="{TemplateBinding PlotAreaStyle}" />
<Border Canvas.ZIndex="10" BorderBrush="#FF919191" BorderThickness="1" />
</chartingPrmtvs:EdgePanel>
</Grid>
<datavis:Legend VerticalAlignment="Top" Grid.Row="2" Header="{TemplateBinding LegendTitle}" Style="{TemplateBinding LegendStyle}" x:Name="Legend"/>
</Grid>
</ControlTemplate>
</charting:Chart.Template>
</charting:Chart>
How can I get the height of ChartArea? Quick Watch shows the value of pieSeries1.ChartArea but this one is not available on Runtime. I also tried FindName but no result.
Should be fairly easy right?
You can add the following in your Chart class:
private EdgePanel panel;
public override void OnApplyTemplate()
{
panel = (EdgePanel)Template.FindName("ChartArea", this);
}
When and how to get the height depends on your own logic needs it.
Eventually I found the solution. The OnApplyTemplate solution from @Bubblewrap did not work, unfortunately.
- I gave my
charting:PieSeriesa name, e.g.pie. - In the code behind I was able to access the
ChartAreaviapie.Parent as EdgePanel.
Create an attached property (say ChartHeight) and bind the value of ActualHeight of ChartArea to it.
After that just check the value in your code.
加载中,请稍侯......
精彩评论