Click here to Skip to main content
15,885,899 members
Articles / Desktop Programming / WPF

OpenWPFChart: assembling charts from components: Part I - Parts

Rate me:
Please Sign up or sign in to vote.
4.29/5 (17 votes)
19 Mar 2009CPOL14 min read 81.8K   4K   81  
Provides the component model along with base components to assemble charts.
<!--
OpenWPFChart library ColumnChart control default style.
Copyright Oleg V. Polikarpotchkin 2008-2009
-->
<!--revision $Id: ColumnChart.Generic.xaml 18093 2009-03-16 04:15:06Z unknown $-->
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:parts="clr-namespace:OpenWPFChart.Parts;assembly=OpenWPFChart.Parts"
    xmlns:local="clr-namespace:OpenWPFChart.Controls">
	
	<!-- ColumnChart Control Style -->
	<Style TargetType="{x:Type local:ColumnChart}">
		<Style.Resources>
			<!-- ColumnChartItem template -->
			<DataTemplate DataType="{x:Type parts:ColumnChartItemDataView}">
				<parts:ColumnChartItem ItemDataView="{Binding}"
					ToolTip="{Binding ItemData.ItemName}" 
					ContextMenu="{Binding Path=ContextMenu, 
						RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ColumnChart}}}"/>
			</DataTemplate>
		</Style.Resources>
		
		<!-- Base ListBox ItemsPanel-->
		<Setter Property="ItemsPanel">
			<Setter.Value>
				<ItemsPanelTemplate>
					<local:ColumnChartPanel />
				</ItemsPanelTemplate>
			</Setter.Value>
		</Setter>
		
		<!-- Base ListBox ItemContainerStyle -->
		<Setter Property="ItemContainerStyle">
			<Setter.Value>
				<Style TargetType="{x:Type ListBoxItem}">
					<Setter Property="Template">
						<Setter.Value>
							<ControlTemplate TargetType="{x:Type ListBoxItem}">
								<ContentPresenter x:Name="ContentHost"
									  SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"/>
								<ControlTemplate.Triggers>
									<Trigger Property="Selector.IsSelected" Value="True">
										<Setter TargetName="ContentHost" Property="BitmapEffect">
											<Setter.Value>
												<DropShadowBitmapEffect Color="Black" Direction="320" 
																		ShadowDepth="5" Softness="0.2" 
																		Opacity="0.8"/>
											</Setter.Value>
										</Setter>
									</Trigger>
								</ControlTemplate.Triggers>
							</ControlTemplate>
						</Setter.Value>
					</Setter>
				</Style>
			</Setter.Value>
		</Setter>

		<!-- ColumnChart Control Template -->
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type local:ColumnChart}">
					<Border Name="Bd"
							BorderThickness="{TemplateBinding Border.BorderThickness}" 
							BorderBrush="{TemplateBinding Border.BorderBrush}" 
							Background="{TemplateBinding Panel.Background}" 
							Padding="1,1,1,1" 
							SnapsToDevicePixels="True">
						<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
								Padding="{TemplateBinding Control.Padding}" Focusable="False">
							<Grid ShowGridLines="False">
								<Grid.RowDefinitions>
									<RowDefinition/>
									<RowDefinition/>
								</Grid.RowDefinitions>
								<Grid.ColumnDefinitions>
									<ColumnDefinition/>
									<ColumnDefinition/>
								</Grid.ColumnDefinitions>

								<!-- Axes are placed into ContentPresenters to provide a way to replace 
								Axis element when related ChartScale derived object type changes. -->

								<!-- Horizontal Bottom axis -->
								<Grid Grid.Row="1" Grid.Column="1" Focusable="False">
									<Grid.Resources>
										<!-- Axis templates -->
										<DataTemplate DataType="{x:Type parts:ChartLinearScale}">
											<parts:LinearAxis AxisScale="{Binding}"
												LabelFormat="{Binding Path=HorizontalAxisLabelFormat, 
													RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ColumnChart}}}"/>
										</DataTemplate>
										<DataTemplate DataType="{x:Type parts:ChartLogarithmicScale}">
											<parts:LogarithmicAxis AxisScale="{Binding}"
												LabelFormat="{Binding Path=HorizontalAxisLabelFormat, 
													RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ColumnChart}}}"/>
										</DataTemplate>
										<DataTemplate DataType="{x:Type parts:ChartDateTimeScale}">
											<parts:DateTimeAxis AxisScale="{Binding}"
												LabelFormat="{Binding Path=HorizontalAxisLabelFormat, 
													RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ColumnChart}}}"/>
										</DataTemplate>
										<DataTemplate DataType="{x:Type parts:ChartSeriesScale}">
											<parts:SeriesAxis AxisScale="{Binding}"
												LabelFormat="{Binding Path=HorizontalAxisLabelFormat, 
													RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ColumnChart}}}"/>
										</DataTemplate>
									</Grid.Resources>
									
									<Grid.RowDefinitions>
										<RowDefinition Height="Auto"/>
										<RowDefinition Height="Auto"/>
									</Grid.RowDefinitions>

									<ContentPresenter Name="PART_HorizontalAxisHost" 
										Content="{TemplateBinding HorizontalScale}" Focusable="False"/>
									<TextBlock Grid.Row="1" HorizontalAlignment="Center"
									   Text="{TemplateBinding HorizontalAxisTitle}"
										Foreground="{Binding RelativeSource={RelativeSource TemplatedParent}
											, Path=(parts:Axis.Pen).Brush}"/>
								</Grid>

								<!-- Vertical Left axis -->
								<Grid Focusable="False">
									<Grid.Resources>
										<!-- Axis templates -->
										<DataTemplate DataType="{x:Type parts:ChartLinearScale}">
											<parts:LinearAxis AxisScale="{Binding}"
												LabelFormat="{Binding Path=VerticalAxisLabelFormat, 
													RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ColumnChart}}}"/>
										</DataTemplate>
										<DataTemplate DataType="{x:Type parts:ChartLogarithmicScale}">
											<parts:LogarithmicAxis AxisScale="{Binding}"
												LabelFormat="{Binding Path=VerticalAxisLabelFormat, 
													RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ColumnChart}}}"/>
										</DataTemplate>
										<DataTemplate DataType="{x:Type parts:ChartDateTimeScale}">
											<parts:DateTimeAxis AxisScale="{Binding}"
												LabelFormat="{Binding Path=VerticalAxisLabelFormat, 
													RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ColumnChart}}}"/>
										</DataTemplate>
										<DataTemplate DataType="{x:Type parts:ChartSeriesScale}">
											<parts:SeriesAxis AxisScale="{Binding}"
												LabelFormat="{Binding Path=VerticalAxisLabelFormat, 
													RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ColumnChart}}}"/>
										</DataTemplate>
									</Grid.Resources>
									
									<Grid.RowDefinitions>
										<RowDefinition Height="Auto"/>
										<RowDefinition Height="Auto"/>
									</Grid.RowDefinitions>

									<ContentPresenter Name="PART_VerticalAxisHost" 
										Content="{TemplateBinding VerticalScale}" Focusable="False"/>
									<TextBlock Grid.Row="1" HorizontalAlignment="Center"
										Text="{TemplateBinding VerticalAxisTitle}"
										Foreground="{Binding RelativeSource={RelativeSource TemplatedParent}
											, Path=(parts:Axis.Pen).Brush}"/>

									<Grid.LayoutTransform>
										<RotateTransform Angle="90"/>
									</Grid.LayoutTransform>
								</Grid>

								<!-- ColumnChart area -->
								<Grid Grid.Column="1">
									<!-- Coordinate grids -->
									<parts:Grid Name="PART_VerticalGrid"
											HorizontalScale="{TemplateBinding HorizontalScale}"
											VerticalScale="{TemplateBinding VerticalScale}"
											GridVisibility="{TemplateBinding VerticalGridVisibility}"
										/>
									<parts:Grid Name="PART_HorizontalGrid" Orientation="Horizontal"
											HorizontalScale="{TemplateBinding HorizontalScale}"
											VerticalScale="{TemplateBinding VerticalScale}"
											GridVisibility="{TemplateBinding HorizontalGridVisibility}"
										/>
									<!-- ColumnChart Items -->
									<ItemsPresenter Name="PART_ItemsHost"
										SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
								</Grid>
							</Grid>
						</ScrollViewer>
					</Border>
					
					<ControlTemplate.Triggers>
						<Trigger Property="UIElement.IsEnabled">
							<Trigger.Value>
								<sys:Boolean>False</sys:Boolean>
							</Trigger.Value>
							<Setter Property="Panel.Background" TargetName="Bd">
								<Setter.Value>
									<DynamicResource ResourceKey="{x:Static SystemColors.ControlBrushKey}" />
								</Setter.Value>
							</Setter>
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
</ResourceDictionary>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions