[英]How to show values for custom property during design-time?
我是WPF C#的新手,我试图创建具有自定义属性的用户控件。 我有一个名为Planet的物业。
这个属性可以取水星,金星,地球和火星的值。
在设计期间,当我在应用程序中包含此控件并键入属性名称时,我希望Visual Studio提示这4个值。 就像我们将Alignment属性用于某些控件时一样,它显示Left,Right,Center。
谁能建议我该怎么做?
这是您需要的:
public class Planet
{
public string mars{ get; set; }
public string earth{ get; set; }
public string Jup{ get; set; }
public string pluto{ get; set; }
}
您需要创建一个枚举类型的Depedency属性。 请参考下面的代码。
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public Planets Planet
{
get { return (Planets)GetValue(PlanetProperty); }
set { SetValue(PlanetProperty, value); }
}
public static readonly DependencyProperty PlanetProperty =
DependencyProperty.Register("Planet", typeof(Planets), typeof(UserControl1), new UIPropertyMetadata(Planets.Mercury));
}
public enum Planets
{
Mercury,
Venus,
Earth,
Mars
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.