C# 在哪里可以找到默认的wpf图表模板?
我正在使用WPFToolKit。我想根据默认图表样式模板更改wpf图表的外观 我注意到图表实例具有一些属性,如标题样式LegendStyle ChartAreaStyle PlotAreaStyle我认为修改这些属性将改变图表的外观C# 在哪里可以找到默认的wpf图表模板?,c#,wpf,templates,charts,wpftoolkit,C#,Wpf,Templates,Charts,Wpftoolkit,我正在使用WPFToolKit。我想根据默认图表样式模板更改wpf图表的外观 我注意到图表实例具有一些属性,如标题样式LegendStyle ChartAreaStyle PlotAreaStyle我认为修改这些属性将改变图表的外观 在哪里可以找到这些默认样式模板?我只是在互联网上搜索了一下,从中找到了一个非常有用的资源。这是WPFToolKit 3.5的更新版本,添加了许多有用的功能,非常感谢作者的工作: 下载源代码,您可以构建/编译以获得System.Windows.Controls.Dat
在哪里可以找到这些默认样式模板?我只是在互联网上搜索了一下,从中找到了一个非常有用的资源。这是WPFToolKit 3.5的更新版本,添加了许多有用的功能,非常感谢作者的工作: 下载源代码,您可以构建/编译以获得System.Windows.Controls.DataVisualization.Toolkit.dll的更新4.0版本 我在源代码中找到了默认模板,如下所示: 默认图表模板:
<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>
以及其他风格,如:
轴样式
<Style TargetType="charting:DisplayAxis">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="TitleStyle">
<Setter.Value>
<Style TargetType="datavis:Title">
<Setter Property="FontStyle" Value="Italic" />
</Style>
</Setter.Value>
</Setter>
<Setter Property="MajorTickMarkStyle">
<Setter.Value>
<Style TargetType="Line">
<Setter Property="Stroke" Value="Black" />
<Setter Property="X2" Value="4" />
<Setter Property="Y2" Value="4" />
</Style>
</Setter.Value>
</Setter>
<Setter Property="GridLineStyle">
<Setter.Value>
<Style TargetType="Line">
<Setter Property="Stroke" Value="Gray" />
</Style>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="charting:DisplayAxis">
<Grid x:Name="AxisGrid" Background="{TemplateBinding Background}">
<datavis:Title x:Name="AxisTitle" Style="{TemplateBinding TitleStyle}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
标题样式:
<Style TargetType="datavis:Title">
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Top" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="datavis:Title">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Cursor="{TemplateBinding Cursor}" Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
图例样式:
<Style TargetType="datavis:Legend">
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="TitleStyle">
<Setter.Value>
<Style TargetType="datavis:Title">
<Setter Property="Margin" Value="0,5,0,10" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="HorizontalAlignment" Value="Center" />
</Style>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="datavis:Legend">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<datavis:Title Grid.Row="0" x:Name="HeaderContent" Content="{TemplateBinding Header}" ContentTemplate="{TemplateBinding HeaderTemplate}" Style="{TemplateBinding TitleStyle}" />
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" BorderThickness="0" Padding="0" IsTabStop="False">
<ItemsPresenter x:Name="Items" Margin="10,0,10,10" />
</ScrollViewer>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
图例项目样式:
<Style TargetType="charting:LegendItem">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="charting:LegendItem">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<StackPanel Orientation="Horizontal">
<Rectangle Width="8" Height="8" Fill="{Binding Background}" Stroke="{Binding BorderBrush}" StrokeThickness="1" Margin="0,0,3,0" />
<datavis:Title Content="{TemplateBinding Content}" />
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
您需要的一切都在源代码中,比如默认的datapointstyle等等。它真的帮了我很多 我只是在互联网上搜索了一下,从中找到了一个非常有用的资源。这是WPFToolKit 3.5的更新版本,添加了许多有用的功能,非常感谢作者的工作: 下载源代码,您可以构建/编译以获得System.Windows.Controls.DataVisualization.Toolkit.dll的更新4.0版本 我在源代码中找到了默认模板,如下所示: 默认图表模板:
<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>
以及其他风格,如:
轴样式
<Style TargetType="charting:DisplayAxis">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="TitleStyle">
<Setter.Value>
<Style TargetType="datavis:Title">
<Setter Property="FontStyle" Value="Italic" />
</Style>
</Setter.Value>
</Setter>
<Setter Property="MajorTickMarkStyle">
<Setter.Value>
<Style TargetType="Line">
<Setter Property="Stroke" Value="Black" />
<Setter Property="X2" Value="4" />
<Setter Property="Y2" Value="4" />
</Style>
</Setter.Value>
</Setter>
<Setter Property="GridLineStyle">
<Setter.Value>
<Style TargetType="Line">
<Setter Property="Stroke" Value="Gray" />
</Style>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="charting:DisplayAxis">
<Grid x:Name="AxisGrid" Background="{TemplateBinding Background}">
<datavis:Title x:Name="AxisTitle" Style="{TemplateBinding TitleStyle}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
标题样式:
<Style TargetType="datavis:Title">
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Top" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="datavis:Title">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Cursor="{TemplateBinding Cursor}" Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
图例样式:
<Style TargetType="datavis:Legend">
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="TitleStyle">
<Setter.Value>
<Style TargetType="datavis:Title">
<Setter Property="Margin" Value="0,5,0,10" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="HorizontalAlignment" Value="Center" />
</Style>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="datavis:Legend">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<datavis:Title Grid.Row="0" x:Name="HeaderContent" Content="{TemplateBinding Header}" ContentTemplate="{TemplateBinding HeaderTemplate}" Style="{TemplateBinding TitleStyle}" />
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" BorderThickness="0" Padding="0" IsTabStop="False">
<ItemsPresenter x:Name="Items" Margin="10,0,10,10" />
</ScrollViewer>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
图例项目样式:
<Style TargetType="charting:LegendItem">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="charting:LegendItem">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<StackPanel Orientation="Horizontal">
<Rectangle Width="8" Height="8" Fill="{Binding Background}" Stroke="{Binding BorderBrush}" StrokeThickness="1" Margin="0,0,3,0" />
<datavis:Title Content="{TemplateBinding Content}" />
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
您需要的一切都在源代码中,比如默认的datapointstyle等等。它真的帮了我很多 您可以直接从Visual Studio提取默认控件模板:
在WPF设计器中,选择相关控件,或将鼠标光标放在XAML中的相关控件上
按F4键打开“属性”窗口
打开杂项类别以查找模板属性,或在窗口顶部的搜索字段中键入模板
单击Template字段右侧的小正方形,然后选择Convert to New Resource。。。选项:
在弹出对话框中,命名要添加的新ControlTemplate并决定要在何处定义它:
点击OK按钮。
摘自问题。您可以直接从Visual Studio提取默认控件模板:
在WPF设计器中,选择相关控件,或将鼠标光标放在XAML中的相关控件上
按F4键打开“属性”窗口
打开杂项类别以查找模板属性,或在窗口顶部的搜索字段中键入模板
单击Template字段右侧的小正方形,然后选择Convert to New Resource。。。选项:
在弹出对话框中,命名要添加的新ControlTemplate并决定要在何处定义它:
点击OK按钮。
摘自问题