0

我通常在 WPF 用户控件中为自定义属性使用描述属性,如下所示。

        [Category("Features"), Description("You can setup image width ratio in double type")]
    public double ImageWidthRatio
    {
        get { return (double)GetValue(ImageWidthRatioProperty); }
        set { SetValue(ImageWidthRatioProperty, value); }
    }

    // Using a DependencyProperty as the backing store for ImageWidthRatioProperty.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty ImageWidthRatioProperty =
        DependencyProperty.Register("ImageWidthRatio", typeof(double), typeof(TheControl), new UIPropertyMetadata(1.0));

该行在[Category("Features"), Description("You can setup image width ratio")]“属性”窗口中给出了组的描述。

但是,是 Windows Store App User Control。它说不System.ComponentModel.DesriptionAttribute

如何在 WinRT 的“属性”窗口中显示我的属性描述?

4

1 回答 1

0

添加这个助手类

using System;

namespace System.ComponentModel
{
    [AttributeUsage(AttributeTargets.All)]
    public class DescriptionAttribute : Attribute
    {
        public DescriptionAttribute(string description)
        {
            Description = description;
        }

        public string Description { get; private set; }

        public override bool Equals(object obj)
        {
            if (obj == this)
                return true;

            var other = obj as DescriptionAttribute;
            return other != null && other.Description == Description;
        }

        public override int GetHashCode()
        {
            return Description.GetHashCode();
        }
    }
}
于 2013-09-04T05:49:45.393 回答