如何让 IntelliSense 在 XAML 中的自定义/用户控件上自动完成枚举? [英] How can I get IntelliSense to auto-complete an enum on a custom/user control in XAML?

查看:14
本文介绍了如何让 IntelliSense 在 XAML 中的自定义/用户控件上自动完成枚举?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
WPF:如何显示枚举属性值在 vs2008 xaml 编辑器智能感知中?

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

In XAML if I am defining the Orientation property for a StackPanel, IntelliSense brings up the Orientation enum. If I'm defining my own control with a DependencyProperty based on an enum, is there a way to get IntelliSense to bring up the enum?

枚举:

public enum MyEnum { Foo, Bar }

DependencyProperty 控制:

DependencyProperty in control:

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

回答Daniel Pratt",因为他为我指明了正确的方向.我更喜欢代码示例.

Giving the answer to "Daniel Pratt", because he pointed me in the right direction. I'd have preferred a code example.

要让它发挥作用:

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

  1. Add the XmlnsDefinition attribute to AssemblyInfo.cs

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

[assembly: XmlnsDefinition("http://schemas.your-company.com/wpf/", "YourNamespace")]

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

In the XAML source where the control will be defined add an xmlns entry for it

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

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

然后,您可以添加控件,IntelliSense 将调出枚举值

Then presto, you can add the control and IntelliSense will bring up the enum values

推荐答案

尝试类似 this 或使用 ReSharper

这篇关于如何让 IntelliSense 在 XAML 中的自定义/用户控件上自动完成枚举?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆