Tho*_*que 92
如果您不需要选择,请使用ItemsControl而不是aListBox
小智 29
在ListBoxItem样式中将Focusable属性添加为false:
<Style x:Key="{x:Type ListBoxItem}" TargetType="{x:Type ListBoxItem}">
<!-- Possibly other setters -->
<Setter Property="Focusable" Value="False" />
</Style>
Run Code Online (Sandbox Code Playgroud)
4im*_*ble 14
如果您不希望它们可选择,那么您可能不想要列表视图.但如果这是你真正需要的,那么你可以用一种风格来做:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<Style x:Key="{x:Type ListBoxItem}" TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border
Name="Border"
Padding="2"
SnapsToDevicePixels="true">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="Border" Property="Background" Value="#DDDDDD"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#888888"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Page.Resources>
<Grid>
<ListBox>
<ListBoxItem>One</ListBoxItem>
<ListBoxItem>Two</ListBoxItem>
<ListBoxItem>Three</ListBoxItem>
</ListBox>
</Grid>
</Page>
Run Code Online (Sandbox Code Playgroud)
查看IsSelected触发器.您可以将边框设置为不同的颜色,使其不是"丑陋"或将其设置为透明,并且在选中时将不可见.
希望这可以帮助.
Asa*_*ani 13
请在列表框中使用此内容.我发现这个非常优雅的解决方案
<ListBox ItemsSource="{Binding YourCollection}">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Focusable" Value="False"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
有一个更简单的方法:set ListBoxproperty IsHitTestVisible="False"。这样可以防止列表中的所有项目接收鼠标事件。这样做的好处是,当您将鼠标悬停在上方时,也可以停止突出显示。
它在WP 7.1中对我有用。