views:

107

answers:

0

This is what I want: I have a custom Panel which arranges a certain type of item. My Panel also has a few dependency properties (ArrangeMode, MinDate, ...), which influence the rendering. Example:

<TimeLinePanel ArrangeMode="Compact" MinDate="...">
    <TimeLineItem ... />
    <TimeLineItem ... />
</TimeLinePanel>

To be able to data-bind this panel to a data source, I've created a custom ItemsControl (TimeLine), which uses a TimeLinePanel as its ItemsPanel and wraps all data items into TimeLineItems:

<TimeLine ItemsSource="{Binding SomeDataTableWithTheFieldsRequiredForTimeLineItems}" />

All of this works perfectly fine. Now, what I would like to do is:

<TimeLine ArrangeMode="Compact" ItemsSource="{Binding SomeDataTable}" />

i.e., I want (most of) the dependency properties of the Panel also available to the custom ItemsControl.


This is what I did: As far as I can see, there are two ways to solve this

  1. Duplicate the dependency properties in the ItemsControl and use data binding in the ItemsControl.ItemsPanel template to bind, e.g., TimeLine.ArrangeMode to TimeLinePanel.ArrangeMode.

  2. Make the TimeLinePanel dependency properties attached, so they can be inherited.

I tried both options and both work fine, but

I don't like option 1, because it forces me to have all the clumsy dependency property code (12 LOC per dependency property in VB) duplicated exactly the same in two classes, and

I don't like option 2, because

<TimeLine TimeLinePanel.ArrangeMode="Compact" TimeLinePanel.MinDate="..." ItemsSource="{Binding SomeDataTable}" />

is non-intuitive on the user side.

Now my question is: Is there some third option that I missed? If not, is there some good reason to prefer either option 1 or 2?