我正在使用http://silverlight.codeplex.com/中的Silverlight Toolkit,并且我遇到了样式问题。根据微软的文档,我看到图表由4个基本组件组成。
ref http://msdn.microsoft.com/en-us/expression/dd433476.aspx
我仍然试图围绕xaml和控制模板等等。我知道它可能是用它完成的,我只是不知道如何。
以下是我想要实现的一个示例:
以下是现在的样子:
答案 0 :(得分:1)
所以我从Toolkit源代码中复制了Chart控件的样式,并从模板中删除了多余的元素。
样式定义看起来如此:
<UserControl.Resources>
<Style x:Key="ChartWithoutPaddings" TargetType="chart:Chart">
<Setter Property="Padding" Value="0" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="ChartAreaStyle">
<Setter.Value>
<Style TargetType="Panel">
<Setter Property="MinWidth" Value="100" />
<Setter Property="MinHeight" Value="20" />
</Style>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="chart:Chart">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
<chartingprimitives:EdgePanel x:Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}">
<Grid Canvas.ZIndex="-1" Style="{TemplateBinding PlotAreaStyle}" />
</chartingprimitives:EdgePanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="EmptyDataPoint" TargetType="Control">
<Setter Property="Background" Value="Black" />
<Setter Property="Template" Value="{x:Null}" />
</Style>
<Style x:Key="OnePixelLine" TargetType="Polyline">
<Setter Property="StrokeThickness" Value="1" />
</Style>
</UserControl.Resources>
您还应该隐藏轴并指定图表的高度和宽度:
<chart:Chart Style="{StaticResource ChartWithoutPaddings}"
VerticalAlignment="Center" HorizontalAlignment="Center"
Width="200" Height="30">
<chart:LineSeries ItemsSource="{Binding Items}" IndependentValuePath="Title" DependentValuePath="Value"
DataPointStyle="{StaticResource EmptyDataPoint}" PolylineStyle="{StaticResource OnePixelLine}" />
<chart:Chart.Axes>
<chart:CategoryAxis Orientation="X" Height="0" Opacity="0" />
<chart:LinearAxis Orientation="Y" Width="0" Opacity="0" />
</chart:Chart.Axes>
</chart:Chart>