简体   繁体   English

如何在ItemsControl中的每个元素周围绘制边框?

[英]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. 我正在使用ItemsControlItemTemplateSelector绘制显示项目的UI。 But now, all my elements need to be inside in a Grid (and one of its columns the element should be there). 但是现在,我所有的元素都必须位于Grid (元素应该在Grid其中一列中)。

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. 起初,我认为将ContentControl嵌套在ItemsControl是正确的,并且此ContentControl应该具有ItemTemplateSelector ,但是我不确定这是否是最好的方法。

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 . 像这样的东西应该放在item容器的Template中,对于ItemsControls来说有点问题,因为容器是没有Template ContentPresenters You could subclass ItemsControl to use a ContentControl , then use the ItemsControl.ItemContainerStyle to edit the Template of those containers. 您可以将ItemsControl子类ItemsControl 使用ContentControl ,然后使用ItemsControl.ItemContainerStyle来编辑这些容器的Template

<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. 我希望这将有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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