如何在列表框项目上设置边框

Ham*_*pus 1 c# wpf xaml

我有一个ListBox从项目源创建项目的项目,我需要每个项目都有一个边框,但是我不知道在哪儿设置ListBox项目样式。

<ListBox x:Name="m_list">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Expander IsExpanded="True">
                <CustomUserControl />
            </Expander>
        </DataTemplate>
    </ListBox.ItemTemplate>
    <ListBox.ItemsSource>
        <Binding Path="DataToBeEditied" />
    </ListBox.ItemsSource>
</ListBox>
Run Code Online (Sandbox Code Playgroud)

自定义用户控件是我创建的用户控件,用于编辑DataToBeEdited中ObservableCollection的数据

根据我的发现,应该有办法,但没有任何解释。我该怎么做?

mm8*_*mm8 5

您可以定义一个ItemContainerStyle

<ListBox>
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="BorderThickness" Value="2" />
            <Setter Property="BorderBrush" Value="Red" />
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>
Run Code Online (Sandbox Code Playgroud)