在WPF中去除ListBox項的單擊樣式,可以通過修改ItemContainerStyle來實現。以下是解決方案:
<ListBox><ListBox.ItemContainerStyle><Style TargetType="ListBoxItem"><Setter Property="Background" Value="Transparent"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="ListBoxItem"><Border Background="{TemplateBinding Background}"><ContentPresenter/></Border></ControlTemplate></Setter.Value></Setter></Style></ListBox.ItemContainerStyle>
</ListBox>
這段代碼通過自定義ListBoxItem的ControlTemplate移除了默認的點擊效果樣式,同時將背景設為透明。你可以根據需要進一步調整邊框和內容展示樣式。