Home > Back-end >  WPF Dependency Property xaml add suggestion / option list
WPF Dependency Property xaml add suggestion / option list

Time:01-25

I have a control where i want to add CharacterCasing since it doesn't support it by default.

I added a custom dependency property called "CharacterCasing". Now when i use it in xaml i want to have the options just like in the normal TextBox:

Example how i want it to look like

Any ideas how to implement the suggestion list in the dependency property?

This is my code in xaml:

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

And this is the dependency property:

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

CodePudding user response:

Because you define it as string. Change the string with CharacterCasing or which kind of enum you want to use.

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); }
}
  •  Tags:  
  • Related