<ControlTemplate TargetType="{x:Type charts:LinearAxis}" x:Key="LinearAxisTemplate">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<Grid x:Name="LayoutRoot" Background="{TemplateBinding Background}">
<Grid x:Name="LabelsContainer"/>
<Canvas x:Name="BehaviourCanvas"/>
<Viewbox Stretch="Uniform" StretchDirection="DownOnly"
Grid.Row="{Binding (Grid.Row), ElementName=AxisLabelContainer}"
Grid.Column="{Binding (Grid.Column), ElementName=AxisLabelContainer}">
<Visiblox_Charts_Primitives:TransposePanel x:Name="AxisLabelContainer">
<TextBlock x:Name="AxisLabel" Style="{TemplateBinding TitleStyle}" Text="{TemplateBinding Title}" />
</Visiblox_Charts_Primitives:TransposePanel>
</Viewbox>
<Line x:Name="AxisLine" Style="{TemplateBinding AxisLineStyle}" Stretch="Fill"/>
</Grid>
</Border>
</ControlTemplate>
只需将此模板应用于任何图表中的任何线性轴,标题就会缩小以适应。您可以轻松地将其调整为任何类型的轴。
(XAxis as LinearAxis).Template = MyChart.FindResource("LinearAxisTemplate") as System.Windows.Controls.ControlTemplate;