如何让 IntelliSense 自动完成 XAML 中自定义/用户控件的枚举? [复制]

2023-12-25

可能的重复:
WPF:如何在 vs2008 xaml 编辑器智能感知中显示枚举属性值? https://stackoverflow.com/questions/419802/wpf-how-to-display-enum-property-values-in-vs2008-xaml-editor-intellisense

在 XAML 中,如果我定义 StackPanel 的 Orientation 属性,IntelliSense 会调出 Orientation 枚举。如果我使用基于枚举的 DependencyProperty 定义自己的控件,是否有办法让 IntelliSense 调出枚举?

Enum:

public enum MyEnum { Foo, Bar }

控制中的依赖属性:

public static readonly DependencyProperty MyEnumValueProperty =
    DependencyProperty.Register(
        "MyEnumValue",
        typeof(MyEnum),
        typeof(MyControl),
        new UIPropertyMetadata());

public MyEnum MyEnumValue
{
    get { return (MyEnum)GetValue(MyEnumValueProperty); }
    set { SetValue(MyEnumValueProperty, value); }
}

EDIT:

给出“丹尼尔·普拉特”的答案,因为他为我指明了正确的方向。我更喜欢一个代码示例。

为了让它发挥作用:

  1. 将 XmlnsDefinition 属性添加到 AssemblyInfo.cs

    [程序集:XmlnsDefinition("http://schemas.your-company.com/wpf/ http://schemas.your-company.com/wpf/", "你的命名空间")]

  2. 在将定义控件的 XAML 源中为其添加一个 xmlns 条目

    xmlns:control="http://schemas.your-company.com/wpf/"

  3. 然后很快,您就可以添加控件了,IntelliSense 将显示枚举值


尝试类似的东西this http://vyasashutosh.blogspot.com/2007/05/providing-custom-intellisense-in-vsnet.html or use 锐锐 http://www.jetbrains.com/resharper/

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何让 IntelliSense 自动完成 XAML 中自定义/用户控件的枚举? [复制] 的相关文章

随机推荐