據我所知,在WPF中沒有相應的狀態。
的WPF ListBoxItem的具有狀態Unselected
,在組SelectionStates
組CommonStates
Selected
和SelectedUnfocused
和各州Normal
,MouseOver
和Disabled
。各組中的國家相互排斥,但可以同時採用不同組別的國家。 ListBoxItem可以例如同時處於狀態Selected
和MouseOver
。
由控制模板來定義考慮到這一事實的可視化。例如,它可以在選中時使用不同的背景畫筆填充項目,並且當鼠標懸停在項目上時繪製外部邊框。重要的是,因爲相關狀態是獨立的並且可以同時進行,所以獨立可視化同時可見。只有當選定的列表項目沒有被選中時,用戶通常會變得有點困惑,因爲他將鼠標移動到該項目上。
編輯 - 列表框例如下。使用觸發器而不是視覺狀態可能會更容易。
<ListBox SelectionMode="Extended">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid Background="LightGray" Margin="1">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="Disabled"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation Storyboard.TargetName="UnselectedText"
Storyboard.TargetProperty="Foreground.Color"
To="Blue" Duration="0:0:0.1"/>
<ColorAnimation Storyboard.TargetName="SelectedText"
Storyboard.TargetProperty="Foreground.Color"
To="Red" Duration="0:0:0.1"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected"/>
<VisualState x:Name="Selected">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="UnselectedText"
Storyboard.TargetProperty="Opacity"
To="0" Duration="0:0:0.1"/>
<DoubleAnimation Storyboard.TargetName="SelectedText"
Storyboard.TargetProperty="Opacity"
To="1" Duration="0:0:0.1"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<TextBlock Name="UnselectedText" Margin="2" Text="{TemplateBinding Content}">
<TextBlock.Foreground>
<SolidColorBrush Color="Black"/>
</TextBlock.Foreground>
</TextBlock>
<TextBlock Name="SelectedText" Margin="2" Text="{TemplateBinding Content}" Opacity="0">
<TextBlock.Foreground>
<SolidColorBrush Color="White"/>
</TextBlock.Foreground>
</TextBlock>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.Items>
<ListBoxItem Content="Item 1"/>
<ListBoxItem Content="Item 2"/>
<ListBoxItem Content="Item 3"/>
<ListBoxItem Content="Item 4"/>
<ListBoxItem Content="Item 5"/>
<ListBoxItem Content="Item 6"/>
<ListBoxItem Content="Item 7"/>
<ListBoxItem Content="Item 8"/>
<ListBoxItem Content="Item 9"/>
<ListBoxItem Content="Item 10"/>
</ListBox.Items>
</ListBox>
對於哪個控件你想SelectedPointerOver狀態...你的意思是任何屬性? –