2011-07-25 5 views
0

툴킷에서 사용할 수있는 LineDataPoint에 대한 리소스 사전에서 사용자 정의 스타일을 사용하고 있습니다.Silverlight LineDataPoint MouseOver의 크기를 늘립니다.

mouseover 이벤트에서 데이터 포인트의 크기를 늘리고 마우스를 놓으면 다시 원래 크기로 되돌리고 싶습니다. 이것을 구현하는 가장 좋은 방법은 무엇입니까? 당신은 일반적인 LineSeries 클래스를 사용하는 경우

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); 
     } 
    } 
} 

이 클래스는 모든 곳에서 사용할 수 있습니다

+0

차트 시리즈의 DataPointStyle 속성이 있습니다. 새 스타일을 만들고 표준 컨트롤 템플릿을 찾고 이벤트 처리기 위에 마우스를 템플릿의 루트 요소에 추가합니다. 나는 그것이 코드 숨김으로 처리 될 수 있다고 생각한다. 내일 내 아이디어를 확인하려고 노력할 것입니다. 쉬운 방법으로 할 수 있습니다. – vorrtex

답변

0

그때 필요한 기능과 확장 클래스를 사용하여 더 나은 솔루션을 발견하지 않았습니다. 포위 된 데이터 포인트의 너비와 높이의 최종 크기를 포함하는 추가 속성 IncreaseDataPointSizeTo이 있습니다. XAML 코드의

예 :

<charting:Chart> 
    <charting:Chart.Series> 
     <ext:ExtendedLineSeries IsSelectionEnabled="True" 
           IncreaseDataPointSizeTo="16" ... 
관련 문제