0

I'm using an ItemsControl and a ItemTemplateSelector to draw display the UI of my items. But now, all my elements need to be inside in a Grid (and one of its columns the element should be there).

At the beginning I supposed was right to have a ContentControl nested in an ItemsControl, and this ContentControl should have the ItemTemplateSelector, but I'm not sure if this is the best way to do it.

H.B.
  • 166,899
  • 29
  • 327
  • 400
Darf Zon
  • 6,268
  • 20
  • 90
  • 149

2 Answers2

2

Stuff like that should be in the Template of the item container, for ItemsControls that is a bit problematic as the containers are ContentPresenters which have no Template. You could subclass ItemsControl to use a ContentControl, then use the ItemsControl.ItemContainerStyle to edit the Template of those containers.

H.B.
  • 166,899
  • 29
  • 327
  • 400
  • thank you. I've investigated a little bit about ´GetContainerForItemOverride´ and this questions helped me. http://stackoverflow.com/questions/3542381/specify-controltemplate-for-itemscontrol-itemcontainerstyle – Darf Zon Aug 05 '12 at 17:03
1
<ItemsControl x:Name="lst">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
            <Border BorderThickness="10" CornerRadius="1" BorderBrush="Navy">
                    <TextBox Text="{Binding Name}"/>
            </Border>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

I hope this will help.

yo chauhan
  • 12,079
  • 4
  • 39
  • 58
  • This sets the same border width for all textboxes in the itemscontrol. Can we have border size depending on the length of the textbox. – Harxish May 23 '23 at 13:44