8,757
社区成员
发帖
与我相关
我的任务
分享
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="charting:Chart">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<datavis:Title Content="{TemplateBinding Title}" Style="{TemplateBinding TitleStyle}" />
<!-- Use a nested Grid to avoid possible clipping behavior resulting from ColumnSpan+Width=Auto -->
<Grid Grid.Row="1" Margin="0,15,0,15">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<datavis:Legend x:Name="Legend" Header="{TemplateBinding LegendTitle}" Style="{TemplateBinding LegendStyle}" Grid.Column="1" />
<chartingprimitives:EdgePanel x:Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}">
<Grid Canvas.ZIndex="-1" Style="{TemplateBinding PlotAreaStyle}" />
<Border Canvas.ZIndex="10" BorderBrush="#FF919191" BorderThickness="1" />
</chartingprimitives:EdgePanel>
</Grid>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
public class Chart : ItemsControl
{
public Chart()
{
this.DefaultStyleKey = typeof(Chart);
}
}
public class LineItem : Control
{
public LineItem()
{
this.DefaultStyleKey = typeof(LineItem);
}
}
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SilverlightApplication15">
<Style TargetType="local:LineItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:LineItem">
<Border BorderBrush="Red" BorderThickness="1"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="local:Chart">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:Chart">
<ScrollViewer Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}" BorderBrush="Transparent" BorderThickness="0" >
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
<custom1:Chart HorizontalAlignment="Left" Margin="70,124,0,0" x:Name="chart1" VerticalAlignment="Top" Height="123" Width="192" BorderBrush="#FF000019" Background="#FFECECF5">
<custom1:LineItem Height="1" Width="148" Margin="8"/>
<custom1:LineItem Height="1" Width="148" Margin="8"/>
<custom1:LineItem Height="1" Width="148" Margin="8"/>
</custom1:Chart>
private void button1_Click(object sender, RoutedEventArgs e)
{
this.chart1.Lines.Add(new LineItem() {
BorderThickness= new Thickness(1) ,
BorderBrush = new SolidColorBrush( Colors.Purple)
});
}
<Style TargetType="local:LineItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:LineItem">
<Border BorderBrush="Red" BorderThickness="1"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="local:Chart">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:Chart">
<ScrollViewer Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}" BorderBrush="Transparent" BorderThickness="0" >
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>