如何在Windows应用商店用户控件中显示属性说明?

时间:2013-09-04 04:55:27

标签: c# user-controls windows-runtime

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

        [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应用商店用户控件。它没有说System.ComponentModel.DesriptionAttribute

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

1 个答案:

答案 0 :(得分: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();
        }
    }
}