views:

80

answers:

2

Hello everybody,

I have a custom panel that has a public dependency property MaxItemsCount(defines the maximum number of elements in the panel), and I am giving this panel as an ItemsPanel to my custom control.

<Setter Property="ItemsPanel">
    <Setter.Value>
     <ItemsPanelTemplate>
      <myPrimitives:MyPanel MaxItemsCount="5"/>
     </ItemsPanelTemplate>
    </Setter.Value>
</Setter>

I also have a public dependency property in my custom control called MaxItemsCount as well.

Is there a way to bind the MaxItemsCount of my panel to the MaxItemsCount of my custom control.

I tried doing the following:

<Setter Property="ItemsPanel">
    <Setter.Value>
     <ItemsPanelTemplate>
      <myPrimitives:MyPanel MaxItemsCount="{TemplateBinding MaxItemsCount}"/>
     </ItemsPanelTemplate>
    </Setter.Value>
</Setter>

...but apparently it's not how it's done.

Any help would be greatly appreciated!

+1  A: 

Assuming your custom control is called MyControl, you could do it like that :

<myPrimitives:MyPanel MaxItemsCount="{Binding MaxItemsCount, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type myPrimitives:MyControl}}}"/>
Thomas Levesque
A: 

Thanks, but the solution you are providing is for WPF only. After some digging, I came to the conclusion that the only way this to happen is via the code-behind.

Kiril