/*
Copyright (C) 2008 Webyog Softworks Private Limited
This file is a part of Visifire Charts.
Visifire is a free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General Public License
along with Visifire Charts. If not, see .
If GPL is not suitable for your products or company, Webyog provides Visifire
under a flexible commercial license designed to meet your specific usage and
distribution requirements. If you have already obtained a commercial license
from Webyog, you can use this file under those license terms.
*/
#if WPF
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using Visifire.Commons;
using System.ComponentModel;
#else
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Visifire.Commons;
using System.Windows.Data;
#endif
namespace Visifire.Charts
{
///
/// Visifire.Charts.Title class
///
#if SL
[System.Windows.Browser.ScriptableType]
#endif
public class Title : ObservableObject
{
#region Public Methods
///
/// Initializes a new instance of the Visifire.Charts.Title class
///
public Title()
{
SetDefaultStyle();
//Bind();
}
///
/// Initializes a new instance of the Visifire.Charts.Title class
///
internal Title(String text)
{
SetDefaultStyle();
Text = text;
//Bind();
}
public override void Bind()
{
#if SL
Binding b = new Binding("FontSize");
b.Source = this;
this.SetBinding(InternalFontSizeProperty, b);
b = new Binding("FontFamily");
b.Source = this;
this.SetBinding(InternalFontFamilyProperty, b);
b = new Binding("FontStyle");
b.Source = this;
this.SetBinding(InternalFontStyleProperty, b);
b = new Binding("FontWeight");
b.Source = this;
this.SetBinding(InternalFontWeightProperty, b);
b = new Binding("BorderThickness");
b.Source = this;
this.SetBinding(InternalBorderThicknessProperty, b);
b = new Binding("Background");
b.Source = this;
this.SetBinding(InternalBackgroundProperty, b);
b = new Binding("HorizontalAlignment");
b.Source = this;
this.SetBinding(InternalHorizontalAlignmentProperty, b);
b = new Binding("VerticalAlignment");
b.Source = this;
this.SetBinding(InternalVerticalAlignmentProperty, b);
b = new Binding("Margin");
b.Source = this;
this.SetBinding(InternalMarginProperty, b);
b = new Binding("Padding");
b.Source = this;
this.SetBinding(InternalPaddingProperty, b);
b = new Binding("Opacity");
b.Source = this;
this.SetBinding(InternalOpacityProperty, b);
#endif
}
#endregion
#region Public Properties
///
/// Identifies the Visifire.Charts.Title.Enabled dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.Enabled dependency property.
///
public static readonly DependencyProperty EnabledProperty = DependencyProperty.Register
("Enabled",
typeof(Nullable),
typeof(Title),
new PropertyMetadata(OnEnabledPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.HrefTarget dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.HrefTarget dependency property.
///
public static readonly DependencyProperty HrefTargetProperty = DependencyProperty.Register
("HrefTarget",
typeof(HrefTargets),
typeof(Title),
new PropertyMetadata(OnHrefTargetChanged));
///
/// Identifies the Visifire.Charts.Title.Href dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.Href dependency property.
///
public static readonly DependencyProperty HrefProperty = DependencyProperty.Register
("Href",
typeof(String),
typeof(Title),
new PropertyMetadata(OnHrefChanged));
///
/// FontSizeProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnFontSizePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
title.InternalFontSize = (Double)e.NewValue;
title.FirePropertyChanged("FontSize");
}
///
/// Identifies the Visifire.Charts.Title.FontColor dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.FontColor dependency property.
///
public static readonly DependencyProperty FontColorProperty = DependencyProperty.Register
("FontColor",
typeof(Brush),
typeof(Title),
new PropertyMetadata(OnFontColorPropertyChanged));
#if SL
///
/// Identifies the Visifire.Charts.Title.FontSize dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.FontSize dependency property.
///
private static readonly DependencyProperty
InternalFontSizeProperty = DependencyProperty.Register
("InternalFontSize",
typeof(Double),
typeof(Title),
new PropertyMetadata(OnFontSizePropertyChanged));
///
/// Identifies the Visifire.Charts.Title.FontFamily dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.FontFamily dependency property.
///
private static readonly DependencyProperty InternalFontFamilyProperty = DependencyProperty.Register
("InternalFontFamily",
typeof(FontFamily),
typeof(Title),
new PropertyMetadata(OnFontFamilyPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.FontStyle dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.FontStyle dependency property.
///
private static readonly DependencyProperty InternalFontStyleProperty = DependencyProperty.Register
("InternalFontStyle",
typeof(FontStyle),
typeof(Title),
new PropertyMetadata(OnFontStylePropertyChanged));
///
/// Identifies the Visifire.Charts.Title.FontWeight dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.FontWeight dependency property.
///
private static readonly DependencyProperty InternalFontWeightProperty = DependencyProperty.Register
("InternalFontWeight",
typeof(FontWeight),
typeof(Title),
new PropertyMetadata(OnFontWeightPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.BorderThickness dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.BorderThickness dependency property.
///
private static readonly DependencyProperty InternalBorderThicknessProperty = DependencyProperty.Register
("InternalBorderThickness",
typeof(Thickness),
typeof(Title),
new PropertyMetadata(OnBorderThicknessPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.Background dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.Background dependency property.
///
private static readonly DependencyProperty InternalBackgroundProperty = DependencyProperty.Register
("InternalBackground",
typeof(Brush),
typeof(Title),
new PropertyMetadata(OnBackgroundPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.HorizontalAlignment dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.HorizontalAlignment dependency property.
///
private static readonly DependencyProperty InternalHorizontalAlignmentProperty = DependencyProperty.Register
("InternalHorizontalAlignment",
typeof(HorizontalAlignment),
typeof(Title),
new PropertyMetadata(OnHorizontalAlignmentPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.VerticalAlignment dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.VerticalAlignment dependency property.
///
private static readonly DependencyProperty InternalVerticalAlignmentProperty = DependencyProperty.Register
("InternalVerticalAlignment",
typeof(VerticalAlignment),
typeof(Title),
new PropertyMetadata(OnVerticalAlignmentPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.Margin dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.Margin dependency property.
///
private static readonly DependencyProperty InternalMarginProperty = DependencyProperty.Register
("InternalMargin",
typeof(Thickness),
typeof(Title),
new PropertyMetadata(OnMarginPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.Padding dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.Padding dependency property.
///
private static readonly DependencyProperty InternalPaddingProperty = DependencyProperty.Register
("InternalPadding",
typeof(Thickness),
typeof(Title),
new PropertyMetadata(OnPaddingPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.Opacity dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.Opacity dependency property.
///
private static readonly DependencyProperty InternalOpacityProperty = DependencyProperty.Register
("InternalOpacity",
typeof(Double),
typeof(Title),
new PropertyMetadata(1.0, OnOpacityPropertyChanged));
#else
///
/// Identifies the Visifire.Charts.Title.FontFamily dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.FontFamily dependency property.
///
public new static readonly DependencyProperty FontFamilyProperty = DependencyProperty.Register
("FontFamily",
typeof(FontFamily),
typeof(Title),
new PropertyMetadata(OnFontFamilyPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.FontSize dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.FontSize dependency property.
///
public new static readonly DependencyProperty FontSizeProperty = DependencyProperty.Register
("FontSize",
typeof(Double),
typeof(Title),
new PropertyMetadata(OnFontSizePropertyChanged));
///
/// Identifies the Visifire.Charts.Title.FontStyle dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.FontStyle dependency property.
///
public new static readonly DependencyProperty FontStyleProperty = DependencyProperty.Register
("FontStyle",
typeof(FontStyle),
typeof(Title),
new PropertyMetadata(OnFontStylePropertyChanged));
///
/// Identifies the Visifire.Charts.Title.FontWeight dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.FontWeight dependency property.
///
public new static readonly DependencyProperty FontWeightProperty = DependencyProperty.Register
("FontWeight",
typeof(FontWeight),
typeof(Title),
new PropertyMetadata(OnFontWeightPropertyChanged));
#endif
///
/// Identifies the Visifire.Charts.Title.Text dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.Text dependency property.
///
public static readonly DependencyProperty TextProperty = DependencyProperty.Register
("Text",
typeof(String),
typeof(Title),
new PropertyMetadata(OnTextPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.BorderColor dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.BorderColor dependency property.
///
public static readonly DependencyProperty BorderColorProperty = DependencyProperty.Register
("BorderColor",
typeof(Brush),
typeof(Title),
new PropertyMetadata(OnBorderColorPropertyChanged));
#if WPF
///
/// Identifies the Visifire.Charts.Title.BorderThickness dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.BorderThickness dependency property.
///
public new static readonly DependencyProperty BorderThicknessProperty = DependencyProperty.Register
("BorderThickness",
typeof(Thickness),
typeof(Title),
new PropertyMetadata(OnBorderThicknessPropertyChanged));
#endif
///
/// Identifies the Visifire.Charts.Title.CornerRadius dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.CornerRadius dependency property.
///
public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register
("CornerRadius",
typeof(CornerRadius),
typeof(Title),
new PropertyMetadata(OnCornerRadiusPropertyChanged));
#if WPF
///
/// Identifies the Visifire.Charts.Title.Background dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.Background dependency property.
///
public new static readonly DependencyProperty BackgroundProperty = DependencyProperty.Register
("Background",
typeof(Brush),
typeof(Title),
new PropertyMetadata(OnBackgroundPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.HorizontalAlignment dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.HorizontalAlignment dependency property.
///
public new static readonly DependencyProperty HorizontalAlignmentProperty = DependencyProperty.Register
("HorizontalAlignment",
typeof(HorizontalAlignment),
typeof(Title),
new PropertyMetadata(OnHorizontalAlignmentPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.VerticalAlignment dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.VerticalAlignment dependency property.
///
public new static readonly DependencyProperty VerticalAlignmentProperty = DependencyProperty.Register
("VerticalAlignment",
typeof(VerticalAlignment),
typeof(Title),
new PropertyMetadata(OnVerticalAlignmentPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.Margin dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.Margin dependency property.
///
public new static readonly DependencyProperty MarginProperty = DependencyProperty.Register
("Margin",
typeof(Thickness),
typeof(Title),
new PropertyMetadata(OnMarginPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.Padding dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.Padding dependency property.
///
public new static readonly DependencyProperty PaddingProperty = DependencyProperty.Register
("Padding",
typeof(Thickness),
typeof(Title),
new PropertyMetadata(OnPaddingPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.Opacity dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.Opacity dependency property.
///
public new static readonly DependencyProperty OpacityProperty = DependencyProperty.Register
("Opacity",
typeof(Double),
typeof(Title),
new PropertyMetadata(1.0, OnOpacityPropertyChanged));
#endif
///
/// Identifies the Visifire.Charts.Title.TextAlignment dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.TextAlignment dependency property.
///
public static readonly DependencyProperty TextAlignmentProperty = DependencyProperty.Register
("TextAlignment",
typeof(TextAlignment),
typeof(Title),
new PropertyMetadata(OnTextAlignmentPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.DockInsidePlotArea dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.DockInsidePlotArea dependency property.
///
public static readonly DependencyProperty DockInsidePlotAreaProperty = DependencyProperty.Register
("DockInsidePlotArea",
typeof(Boolean),
typeof(Title),
new PropertyMetadata(OnDockInsidePlotAreaPropertyChanged));
///
/// Get or set the Enabled property of title
///
[System.ComponentModel.TypeConverter(typeof(NullableBoolConverter))]
public Nullable Enabled
{
get
{
if ((Nullable)GetValue(EnabledProperty) == null)
return true;
else
return (Nullable)GetValue(EnabledProperty);
}
set
{
SetValue(EnabledProperty, value);
}
}
///
/// Get or set the HrefTarget property of title
///
public HrefTargets HrefTarget
{
get
{
return (HrefTargets)GetValue(HrefTargetProperty);
}
set
{
SetValue(HrefTargetProperty, value);
}
}
///
/// Get or set the Href property of title
///
public String Href
{
get
{
return (String) GetValue(HrefProperty);
}
set
{
SetValue(HrefProperty, value);
}
}
///
/// Get or set the Opacity property
///
public new Double Opacity
{
get
{
return (Double)GetValue(OpacityProperty);
}
set
{
#if SL
if (Opacity != value)
{
InternalOpacity = value;
SetValue(OpacityProperty, value);
FirePropertyChanged("Opacity");
}
#else
SetValue(OpacityProperty, value);
#endif
}
}
///
/// Get or set the Opacity property
///
internal Double InternalOpacity
{
get
{
return (Double)(Double.IsNaN(_internalOpacity) ? GetValue(OpacityProperty) : _internalOpacity);
}
set
{
_internalOpacity = value;
}
}
Double _internalOpacity = Double.NaN;
///
/// Get or set the Cursor property
///
public new Cursor Cursor
{
get
{
return base.Cursor;
}
set
{
if (base.Cursor != value)
{
base.Cursor = value;
FirePropertyChanged("Cursor");
}
}
}
#region Font Properties
///
/// Get or set the FontFamily property of title
///
public new FontFamily FontFamily
{
get
{
FontFamily retVal;
if (_internalFontFamily == null)
retVal = (FontFamily)GetValue(FontFamilyProperty);
else
retVal =_internalFontFamily;
return(retVal == null)? new FontFamily("Verdana") : (FontFamily)GetValue(FontFamilyProperty);
}
set
{
#if SL
if (InternalFontFamily != value)
{
_internalFontFamily = value;
SetValue(FontFamilyProperty, value);
FirePropertyChanged("FontFamily");
}
#else
SetValue(FontFamilyProperty, value);
#endif
}
}
///
/// Get or set the FontFamily property of title
///
internal FontFamily InternalFontFamily
{
get
{
FontFamily retVal;
if (_internalFontFamily == null)
retVal = (FontFamily)GetValue(FontFamilyProperty);
else
retVal = _internalFontFamily;
return (retVal == null) ? new FontFamily("Verdana") : retVal;
}
set
{
_internalFontFamily = value;
}
}
///
///Get or set the FontSize property of title
///
public new Double FontSize
{
get
{
return (Double)GetValue(FontSizeProperty);
}
set
{
#if SL
if (FontSize != value)
{
InternalFontSize = value;
SetValue(FontSizeProperty, value);
FirePropertyChanged("FontSize");
}
#else
SetValue(FontSizeProperty, value);
#endif
}
}
///
/// Get or set the FontSize property of title
///
internal Double InternalFontSize
{
get
{
if (Double.IsNaN(_internalFontSize))
return ((Double)GetValue(FontSizeProperty) == 0) ? 10 : (Double)GetValue(FontSizeProperty);
else
return (_internalFontSize == 0) ? 10 : _internalFontSize;
}
set
{
_internalFontSize = value;
}
}
private Double _internalFontSize = Double.NaN;
private FontFamily _internalFontFamily = null;
///
/// Get or set the FontColor property of title text
///
public Brush FontColor
{
get
{
return (Brush)GetValue(FontColorProperty);
}
set
{
SetValue(FontColorProperty, value);
}
}
internal Brush InternalFontColor;
///
/// Get or set the FontStyle property of title text
///
#if WPF
[TypeConverter(typeof(System.Windows.FontStyleConverter))]
#endif
public new FontStyle FontStyle
{
get
{
return (FontStyle)(GetValue(FontStyleProperty));
}
set
{
#if SL
if (InternalFontStyle != value)
{
_internalFontStyle = value;
SetValue(FontStyleProperty, value);
UpdateVisual("FontStyle", value);
}
#else
SetValue(FontStyleProperty, value);
#endif
}
}
///
/// Get or set the FontStyle property of title text
///
#if WPF
[TypeConverter(typeof(System.Windows.FontStyleConverter))]
#endif
internal FontStyle InternalFontStyle
{
get
{
return (FontStyle)((_internalFontStyle == null) ? GetValue(FontStyleProperty) : _internalFontStyle);
}
set
{
_internalFontStyle = value;
}
}
Nullable _internalFontStyle = null;
///
/// Get or set the FontWeight property of title text
///
#if WPF
[System.ComponentModel.TypeConverter(typeof(System.Windows.FontWeightConverter))]
#endif
public new FontWeight FontWeight
{
get
{
return (FontWeight)(GetValue(FontWeightProperty));
}
set
{
#if SL
if (FontWeight != value)
{
_internalFontWeight = value;
SetValue(FontWeightProperty, value);
UpdateVisual("FontWeight", value);
}
#else
SetValue(FontWeightProperty, value);
#endif
}
}
///
/// Get or set the FontWeight property of title text
///
#if WPF
[System.ComponentModel.TypeConverter(typeof(System.Windows.FontWeightConverter))]
#endif
internal FontWeight InternalFontWeight
{
get
{
return(FontWeight)((_internalFontWeight == null) ? GetValue(FontWeightProperty):_internalFontWeight);
}
set
{
_internalFontWeight = value;
}
}
Nullable _internalFontWeight = null;
///
/// Get or set the Text property of title
///
public String Text
{
get
{
return (GetValue(TextProperty) == null) ? "": (String)GetValue(TextProperty);
}
set
{
SetValue(TextProperty, value);
}
}
#endregion
#region Border Properties
///
/// Get or set the BorderColor property of title
///
public Brush BorderColor
{
get
{
return (Brush)GetValue(BorderColorProperty);
}
set
{
SetValue(BorderColorProperty, value);
}
}
///
/// Get or set the BorderThickness of title
///
public new Thickness BorderThickness
{
get
{
return (Thickness)GetValue(BorderThicknessProperty);
}
set
{
#if SL
if (BorderThickness != value)
{
_borderThickness = value;
SetValue(BorderThicknessProperty, value);
FirePropertyChanged("BorderThickness");
}
#else
SetValue(BorderThicknessProperty, value);
#endif
}
}
///
/// Get or set the BorderThickness of title
///
internal Thickness InternalBorderThickness
{
get
{
return (Thickness)((_borderThickness == null) ? GetValue(BorderThicknessProperty) : _borderThickness);
}
set
{
_borderThickness = value;
}
}
Nullable _borderThickness = null;
///
/// Get or set the CornerRadius property of title
///
#if WPF
[System.ComponentModel.TypeConverter(typeof(System.Windows.CornerRadiusConverter))]
#else
[System.ComponentModel.TypeConverter(typeof(Converters.CornerRadiusConverter))]
#endif
public CornerRadius CornerRadius
{
get
{
return (CornerRadius)GetValue(CornerRadiusProperty);
}
set
{
SetValue(CornerRadiusProperty, value);
}
}
#endregion
///
/// Get or set the Background property of title
///
public new Brush Background
{
get
{
return (Brush)GetValue(BackgroundProperty);
}
set
{
#if SL
if (Background != value)
{
_internalBackground = value;
SetValue(BackgroundProperty, value);
UpdateVisual("Background", value);
// FirePropertyChanged("Background");
}
#else
SetValue(BackgroundProperty, value);
#endif
}
}
///
/// Get or set the Background property of title
///
internal Brush InternalBackground
{
get
{
return (Brush)((_internalBackground == null) ? GetValue(BackgroundProperty) : _internalBackground);
}
set
{
_internalBackground = value;
}
}
Brush _internalBackground = null;
#region Alignment
///
/// Get or set the HorizontalAlignment property of title
///
public new HorizontalAlignment HorizontalAlignment
{
get
{
return (HorizontalAlignment)GetValue(HorizontalAlignmentProperty);
}
set
{
#if SL
if (HorizontalAlignment != value)
{
InternalHorizontalAlignment = value;
SetValue(HorizontalAlignmentProperty, value);
FirePropertyChanged("HorizontalAlignment");
}
#else
SetValue(HorizontalAlignmentProperty, value);
#endif
}
}
///
/// Get or set the HorizontalAlignment property of title
///
internal HorizontalAlignment InternalHorizontalAlignment
{
get
{
return (HorizontalAlignment)((_internalHorizontalAlignment == null) ? GetValue(HorizontalAlignmentProperty) : _internalHorizontalAlignment);
}
set
{
_internalHorizontalAlignment = value;
}
}
Nullable _internalHorizontalAlignment = null;
///
/// Get or set the VerticalAlignment property of title
///
public new VerticalAlignment VerticalAlignment
{
get
{
return (VerticalAlignment)GetValue(VerticalAlignmentProperty);
}
set
{
#if SL
if (VerticalAlignment != value)
{
InternalVerticalAlignment = value;
SetValue(VerticalAlignmentProperty, value);
FirePropertyChanged("VerticalAlignment");
}
#else
SetValue(VerticalAlignmentProperty, value);
#endif
}
}
///
/// Get or set the VerticalAlignment property of title
///
internal VerticalAlignment InternalVerticalAlignment
{
get
{
return (VerticalAlignment)((_internalVerticalAlignment == null) ? GetValue(VerticalAlignmentProperty) : _internalVerticalAlignment);
}
set
{
_internalVerticalAlignment = value;
}
}
Nullable _internalVerticalAlignment = null;
#endregion
///
/// Get or set the Margin property of title
///
public new Thickness Margin
{
get
{
return (Thickness)GetValue(MarginProperty);
}
set
{
#if SL
if (Margin != value)
{
InternalMargin = value;
SetValue(MarginProperty, value);
FirePropertyChanged("Margin");
}
#else
SetValue(MarginProperty, value);
#endif
}
}
///
/// Get or set the Margin property of title
///
internal Thickness InternalMargin
{
get
{
return (Thickness)((_internalMargin == null) ? GetValue(MarginProperty) : _internalMargin);
}
set
{
_internalMargin = value;
}
}
Nullable _internalMargin = null;
///
/// Get or set the Padding property of title
///
public new Thickness Padding
{
get
{
return (Thickness)GetValue(PaddingProperty);
}
set
{
#if SL
if (Padding != value)
{
InternalPadding = value;
SetValue(PaddingProperty, value);
FirePropertyChanged("Padding");
}
#else
SetValue(PaddingProperty, value);
#endif
}
}
///
/// Get or set the Padding property of title
///
public Thickness InternalPadding
{
get
{
return (Thickness)((_internalPadding == null) ? GetValue(PaddingProperty) : _internalPadding);
}
set
{
_internalPadding = value;
}
}
Nullable _internalPadding = null;
///
/// Get or set the Property property TextAlignment
///
public TextAlignment TextAlignment
{
get
{
return (TextAlignment)GetValue(TextAlignmentProperty);
}
set
{
SetValue(TextAlignmentProperty, value);
}
}
///
/// Get or set the DockInsidePlotArea property of title
/// (Whether the title will be docked inside PlotArea)
///
public Boolean DockInsidePlotArea
{
get
{
return (Boolean)GetValue(DockInsidePlotAreaProperty);
}
set
{
SetValue(DockInsidePlotAreaProperty, value);
}
}
#endregion
#region Public Events
#endregion
#region Protected Methods
#endregion
#region Internal Properties
///
/// Visual is the Framework object to be used to render the title
///
internal Border Visual
{
get;
#if DEBUG
set;
#else
private set;
#endif
}
///
/// TextBlock desired size
///
internal Size TextBlockDesiredSize
{
get;
set;
}
#endregion
#region Private Delegates
#endregion
#region Private Properties
#region Hidden Properties
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
private new Brush BorderBrush
{
get;
set;
}
private new Brush Foreground
{
get;
set;
}
#endregion
///
/// Canvas inside Title Visual
///
private Canvas InnerCanvas
{
get;
set;
}
///
/// Text element of the title to display text content
///
internal TextBlock TextElement
{
get;
set;
}
#endregion
#region Private Methods
///
/// EnabledProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
title.FirePropertyChanged("Enabled");
}
///
/// HrefTargetProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnHrefTargetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
title.FirePropertyChanged("HrefTarget");
}
///
/// HrefProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnHrefChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
title.FirePropertyChanged("Href");
}
///
/// FontFamilyProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnFontFamilyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
if (e.NewValue == null || e.OldValue == null)
{
title.InternalFontFamily = (FontFamily)e.NewValue;
title.FirePropertyChanged("FontFamily");
}
else if (e.NewValue.ToString() != e.OldValue.ToString())
{
title.InternalFontFamily = (FontFamily)e.NewValue;
title.FirePropertyChanged("FontFamily");
}
}
///
/// OpacityProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnOpacityPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
title.InternalOpacity = (Double)e.NewValue;
title.FirePropertyChanged("Opacity");
}
///
/// FontColorProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnFontColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
title.InternalFontColor = (Brush) e.NewValue;
title.UpdateVisual("FontColor", e.NewValue);
}
///
/// FontStyleProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnFontStylePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
title.InternalFontStyle = (FontStyle)e.NewValue;
title.UpdateVisual("FontStyle", e.NewValue);
}
///
/// FontWeightProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnFontWeightPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
title.InternalFontWeight = (FontWeight)e.NewValue;
title.UpdateVisual("FontWeight", e.NewValue);
}
#if WPF
#endif
///
/// TextProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
title.FirePropertyChanged("Text");
}
///
/// BorderColorProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnBorderColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
// title.FirePropertyChanged("BorderColor");
title.UpdateVisual("BorderColor", e.NewValue);
}
///
/// BorderThicknessProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnBorderThicknessPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
title.InternalBorderThickness = (Thickness)e.NewValue;
title.FirePropertyChanged("BorderThickness");
}
///
/// CornerRadiusProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnCornerRadiusPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
title.FirePropertyChanged("CornerRadius");
}
///
/// BackgroundProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnBackgroundPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
title._internalBackground = (Brush)e.NewValue;
title.UpdateVisual("Background", e.NewValue);
}
///
/// HorizontalAlignmentProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnHorizontalAlignmentPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
title.InternalHorizontalAlignment = (HorizontalAlignment) e.NewValue;
title.FirePropertyChanged("HorizontalAlignment");
}
///
/// VerticalAlignmentProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnVerticalAlignmentPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
title.InternalVerticalAlignment = (VerticalAlignment) e.NewValue;
title.FirePropertyChanged("VerticalAlignment");
}
///
/// MarginProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnMarginPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
title.InternalMargin = (Thickness)e.NewValue;
title.FirePropertyChanged("Margin");
}
///
/// PaddingProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnPaddingPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
title.InternalPadding = (Thickness)e.NewValue;
title.FirePropertyChanged("Padding");
}
///
/// TextAlignmentProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnTextAlignmentPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
title.FirePropertyChanged("TextAlignment");
}
///
/// DockInsidePlotAreaProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnDockInsidePlotAreaPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Title title = d as Title;
title.FirePropertyChanged("DockInsidePlotArea");
}
///
/// Set default style for title
///
private void SetDefaultStyle()
{
// Apply default style from generic
#if WPF
if (!_defaultStyleKeyApplied)
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(Title), new FrameworkPropertyMetadata(typeof(Title)));
_defaultStyleKeyApplied = true;
}
#else
DefaultStyleKey = typeof(Title);
#endif
}
///
/// Apply all style properties of the Title
///
/// Title
/// Boolean
private static Boolean ApplyProperties(Title title)
{
if (title.Visual != null)
{
// Set TextElement properties
#if WPF
title.Visual.FlowDirection = FlowDirection.LeftToRight;
#endif
title.TextElement.FontFamily = title.InternalFontFamily;
title.TextElement.FontSize = title.InternalFontSize;
//Binding fbinding = new Binding("FontSize");
//fbinding.Source = title;
//fbinding.Mode = BindingMode.TwoWay;
//title.TextElement.SetBinding(TextBlock.FontSizeProperty, fbinding);
title.TextElement.FontStyle = title.InternalFontStyle;
title.TextElement.FontWeight = title.InternalFontWeight;
title.TextElement.Text = GetFormattedMultilineText(title.Text);
title.TextElement.Foreground = Charts.Chart.CalculateFontColor((title.Chart as Chart), title.InternalFontColor, title.DockInsidePlotArea);
title.TextElement.TextWrapping = TextWrapping.Wrap;
// Set Border Properties
title.Visual.BorderBrush = title.BorderColor;
//Binding binding = new Binding("Background");
//binding.Source = title;
//binding.Mode = BindingMode.TwoWay;
//title.Visual.SetBinding(Border.BackgroundProperty, binding);
title.Visual.Background = title.InternalBackground;
title.Visual.VerticalAlignment = title.InternalVerticalAlignment;
title.Visual.HorizontalAlignment = title.InternalHorizontalAlignment;
title.Visual.BorderThickness = title.InternalBorderThickness;
title.Visual.Margin = title.InternalMargin;
title.Visual.Padding = title.InternalPadding;
title.Visual.CornerRadius = title.CornerRadius;
title.Visual.Cursor = (title.Cursor == null)? Cursors.Arrow : title.Cursor;
title.Visual.SetValue(Canvas.ZIndexProperty, title.GetValue(Canvas.ZIndexProperty));
title.AttachToolTip(title.Chart, title, title.TextElement);
title.AttachHref(title.Chart, title.TextElement, title.Href, title.HrefTarget);
return true;
}
else
return false;
}
#endregion
#region Internal Methods
///
/// UpdateVisual is used for partial rendering
///
/// Name of the property
/// Value of the property
internal override void UpdateVisual(String propertyName, Object value)
{
if (propertyName == "Background")
{
if (Visual != null)
{
Binding binding = new Binding("Background");
binding.Source = this;
binding.Mode = BindingMode.TwoWay;
Visual.SetBinding(Border.BackgroundProperty, binding);
}
else
this.FirePropertyChanged(propertyName);
}
else if (propertyName == "BorderColor")
{
if (Visual != null)
{
Visual.BorderBrush = (Brush)value;
// Binding binding = new Binding("Background");
// binding.Source = this;
// binding.Mode = BindingMode.TwoWay;
// Visual.SetBinding(Border.BackgroundProperty, binding);
}
else
this.FirePropertyChanged(propertyName);
}
else if (!ApplyProperties(this))
this.FirePropertyChanged(propertyName);
}
///
/// Set TextAlignment for Titles present in Left and Right of the ChartArea
///
internal void SetTextAlignment4LeftAndRight()
{
switch (TextAlignment)
{
case TextAlignment.Left: InnerCanvas.VerticalAlignment = VerticalAlignment.Bottom; break;
case TextAlignment.Center: InnerCanvas.VerticalAlignment = VerticalAlignment.Center; break;
case TextAlignment.Right: InnerCanvas.VerticalAlignment = VerticalAlignment.Top; break;
}
}
///
/// Set TextAlignment for Titles present in Top and Bottom of the ChartArea
///
internal void SetTextAlignment4TopAndBottom()
{
switch (TextAlignment)
{
case TextAlignment.Left: InnerCanvas.HorizontalAlignment = HorizontalAlignment.Left; break;
case TextAlignment.Center: InnerCanvas.HorizontalAlignment = HorizontalAlignment.Center; break;
case TextAlignment.Right: InnerCanvas.HorizontalAlignment = HorizontalAlignment.Right; break;
}
}
///
/// Creates the Title visual object
///
internal void CreateVisualObject(ElementData tag)
{
if (!(Boolean)Enabled)
return;
// Creating Title Visual Object
Visual = new Border();
TextElement = new TextBlock() { Tag = tag };
InnerCanvas = new Canvas() { Tag = tag };
InnerCanvas.Children.Add(TextElement);
Visual.Child = InnerCanvas;
Visual.Opacity = this.InternalOpacity;
// Set Properties
ApplyProperties(this);
#if WPF
TextElement.Measure(new Size(Double.MaxValue, Double.MaxValue));
TextBlockDesiredSize = new Size(TextElement.DesiredSize.Width, TextElement.DesiredSize.Height);
#else
TextBlockDesiredSize = new Size(TextElement.ActualWidth, TextElement.ActualHeight);
#endif
// Set TextElement position inside Title Visual
if (InternalVerticalAlignment == VerticalAlignment.Center || InternalVerticalAlignment == VerticalAlignment.Stretch)
{
if (InternalHorizontalAlignment == HorizontalAlignment.Left || InternalHorizontalAlignment == HorizontalAlignment.Right)
{
RotateTransform rt = new RotateTransform();
rt.Angle = 270;
TextElement.RenderTransformOrigin = new Point(0, 0);
TextElement.RenderTransform = rt;
InnerCanvas.Height = TextBlockDesiredSize.Width;
InnerCanvas.Width = TextBlockDesiredSize.Height;
TextElement.SetValue(Canvas.LeftProperty, (Double)0);
TextElement.SetValue(Canvas.TopProperty, (Double)TextBlockDesiredSize.Width);
SetTextAlignment4LeftAndRight();
}
else
{
InnerCanvas.Height = TextBlockDesiredSize.Height;
InnerCanvas.Width = TextBlockDesiredSize.Width;
SetTextAlignment4TopAndBottom();
}
}
else
{
InnerCanvas.Height = TextBlockDesiredSize.Height;
InnerCanvas.Width = TextBlockDesiredSize.Width;
}
this.Height = InnerCanvas.Height;
this.Width = InnerCanvas.Width;
SetTextAlignment4TopAndBottom();
// Attach event to title visual object
AttachEvents2Visual(this, TextElement);
}
#endregion
#region Internal Events
#endregion
#region Data
#if WPF
///
/// Whether the default style is applied
///
private static Boolean _defaultStyleKeyApplied;
#endif
#endregion Data
}
}