【问题标题】:WPF Dependency Property xaml add suggestion / option listWPF 依赖属性 xaml 添加建议/选项列表
【发布时间】:2022-01-24 22:19:07
【问题描述】:

我有一个控件,我想在其中添加 CharacterCasing,因为它默认不支持。

我添加了一个名为“CharacterCasing”的自定义依赖项属性。 现在,当我在 xaml 中使用它时,我希望拥有与普通 TextBox 中一样的选项:

任何想法如何在依赖属性中实现建议列表?

这是我在 xaml 中的代码:

<TestControl:APTextBox CharacterCasing="UpperCase" Text="{Binding AktuelleZeile.LKR, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnDataErrors=True}">

这是依赖属性:

public static readonly DependencyProperty CharacterCasingProperty =
      DependencyProperty.Register(name: "CharacterCasing",
                                   propertyType: typeof(string),
                                   ownerType: typeof(APTextBox),
                                   typeMetadata: new PropertyMetadata("Normal"));

public string CharacterCasing
{
    get { return (string)this.GetValue(CharacterCasingProperty); }
    set { this.SetValue(CharacterCasingProperty, value); }
}

【问题讨论】:

标签: c# wpf xaml properties dependencies


【解决方案1】:

因为您将其定义为字符串。使用 CharacterCasing 或您要使用的枚举类型更改字符串。

public static readonly DependencyProperty CharacterCasingProperty =
  DependencyProperty.Register(name: "CharacterCasing",
                               propertyType: typeof(CharacterCasing),
                               ownerType: typeof(APTextBox),
                               typeMetadata: new PropertyMetadata(CharacterCasing.Normal));

public CharacterCasing CharacterCasing
{
    get { return (CharacterCasing)this.GetValue(CharacterCasingProperty); }
    set { this.SetValue(CharacterCasingProperty, value); }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-01
    • 2015-11-03
    • 2014-07-29
    相关资源
    最近更新 更多