Silverlight LineDataPoint 增加鼠标悬停时的大小

发布于 2024-11-26 03:21:07 字数 102 浏览 1 评论 0原文

我在资源字典中为工具包提供的 LineDataPoint 使用自定义样式。

我希望数据点在鼠标悬停事件上增加大小,并在鼠标离开后恢复到其原始大小。实现这一点的最佳方法是什么?

I am using a custom style in a resource dictionary for the LineDataPoint available with the toolkit.

I want the datapoint to increase in size on the mouseover event and the revert back to its original size once the mouse leaves. What's the best way to implement this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悍妇囚夫 2024-12-03 03:21:07

我还没有找到比使用具有必要功能的扩展类更好的解决方案:

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" ...

I haven't found a better solution then using an extended class with necessary functionality:

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

This class can be used everywhere where you use the common LineSeries class. It has the additional property IncreaseDataPointSizeTo which contains the final size in width and height of the hovered datapoint.

Example of xaml code:

<charting:Chart>
    <charting:Chart.Series>
        <ext:ExtendedLineSeries IsSelectionEnabled="True"
                                IncreaseDataPointSizeTo="16" ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文