0

I have a made a Subclass of ListBox and ListBoxItem in WPF because I want to add some custom Dependency Properties to both controls. I have used this example:To override the container rendering of the ListBox, to fill the Box with my Custom ListBoxItems

The code to make this happen looks like this:

        protected override DependencyObject GetContainerForItemOverride()
    {
        CustomBoxItem container = new CustomBoxItem();

        return container;
    }

This works great but my question is: do I have to set all the dependency properties by hand? Because in my CustomBox.Xaml I cannot set Dependency Properties in the root tag. I would like to do this in the xaml:

<UserControl mycustomdp="SomeValue">

I know I can set the DP in the sample code above by doing this:

container.mycustomdp = "SomeValue";

But when I want to set bindings it's going to be much less elegant than setting the properties in XAML. Is this possible?

Community
  • 1
  • 1
Audio
  • 307
  • 1
  • 4
  • 14

0 Answers0