Jan Kučera

Hello,

how can I make use of ItemsPanel template in custom control I would like to use panel in my custom items control, but I'd like it to be changeable by template. What's the right XAML to accomplish this

Thanks, Jan



Re: Windows Presentation Foundation (WPF) ItemsPanelTemplate in custom control

Yi-Lun Luo - MSFT

First you must derive your Control from ItemsControl or one of its descendent. If you want your items to be selectable, you¡¯d better derive from Selector or one of its descendent, such as ListBox. Then in XAML, you must create a Panel and set its IsItemsHost property to true:

<StackPanel IsItemsHost="True" />

You can use any kind of Panels. But make sure you don¡¯t add anything in this Panel. It must be empty. Also make sure your users won¡¯t override your template and remove this Panel¡­ Well, if you don¡¯t need to provide any functionality other then changing the look and items layout from ListBox, I suggest you create a ControlTemplate rather than create a custom control.






Re: Windows Presentation Foundation (WPF) ItemsPanelTemplate in custom control

Jan Ku?era

What if I can't derive from ItemsControl or I'd like to change another panel than the one for the Items collection of ItemsControl



Re: Windows Presentation Foundation (WPF) ItemsPanelTemplate in custom control

Martin_Moser

I don't think you have any choice to derive from ItemsControl, except to code everything by yourself.



Re: Windows Presentation Foundation (WPF) ItemsPanelTemplate in custom control

Jan Ku?era

Okay, any clue how ItemsPanelTemplate is implemented Kind of PART_