简体   繁体   中英

How to draw a border around each element in ItemsControl?

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.

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.

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM