0
我在資源字典中爲工具包提供的LineDataPoint使用了自定義樣式。Silverlight LineDataPoint在MouseOver上增加大小
我希望數據點在鼠標懸停事件上增加大小,並在鼠標離開後恢復爲其原始大小。實現這個最好的方法是什麼?
我在資源字典中爲工具包提供的LineDataPoint使用了自定義樣式。Silverlight LineDataPoint在MouseOver上增加大小
我希望數據點在鼠標懸停事件上增加大小,並在鼠標離開後恢復爲其原始大小。實現這個最好的方法是什麼?
我還沒有找到一個更好的解決方案,然後使用擴展類必需的功能:
public class ExtendedLineSeries : LineSeries
{
//I assume that all points have the same size
private double _originalDataPointWidth;
private double _originalDataPointHeight;
protected override DataPoint CreateDataPoint()
{
var dp = base.CreateDataPoint();
if (this.IncreaseDataPointSizeTo != null)
{
dp.MouseEnter += new MouseEventHandler(OnDataPointMouseEnter);
dp.MouseLeave += new MouseEventHandler(OnDataPointMouseLeave);
}
return dp;
}
/// <summary>
/// The width and height to which the point is increased in size
/// </summary>
public double? IncreaseDataPointSizeTo { get; set; }
void OnDataPointMouseLeave(object sender, MouseEventArgs e)
{
var dp = sender as DataPoint;
if (dp != null)
{
//return to the original size
dp.Width = _originalDataPointWidth;
dp.Height = _originalDataPointHeight;
dp.UpdateLayout();
base.UpdateDataPoint(dp);
}
}
void OnDataPointMouseEnter(object sender, MouseEventArgs e)
{
var dp = sender as DataPoint;
if (dp != null)
{
//remember the original size and enlarge the data point
_originalDataPointWidth = dp.ActualWidth;
_originalDataPointHeight = dp.ActualHeight;
dp.Width = dp.Height = IncreaseDataPointSizeTo.Value;
dp.UpdateLayout();
base.UpdateDataPoint(dp);
}
}
}
這個類可以到處在您使用普通LineSeries
類中使用。它具有附加屬性IncreaseDataPointSizeTo
,其中包含懸停數據點的寬度和高度的最終大小。的XAML代碼
實施例:
<charting:Chart>
<charting:Chart.Series>
<ext:ExtendedLineSeries IsSelectionEnabled="True"
IncreaseDataPointSizeTo="16" ...
有的圖表系列的DataPointStyle屬性。創建一個新的樣式,找到標準的控件模板,將鼠標懸停在事件處理程序上,添加到模板的根元素中。我認爲它可以在代碼隱藏中處理。我會盡量明天檢查我的想法,這可能會以簡單的方式完成。 – vorrtex