0

当我编辑模板并进入 ItemContainerStyle 模板时,状态被定义为 Unselected、Selected、MouseOver 等。但实际上没有对这些状态进行任何操作。这种行为正常吗?我使用过 Silverlight 列表框。在其中,ItemContainerStyle 确实定义了所有状态,并且许多属性都已更改。WPF 列表框有点令人困惑。看到这是我编辑 ItemContainerStyle 时的 xaml:

<Style x:Key="ListBoxItemContainerStyle" TargetType="{x:Type ListBoxItem}">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
            <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
            <Setter Property="Padding" Value="2,0,0,0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                        <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true" >
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver"/>
                                    <VisualState x:Name="Disabled"/>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="SelectionStates">
                                    <VisualState x:Name="Unselected"/>
                                    <VisualState x:Name="Selected"/>
                                    <VisualState x:Name="SelectedUnfocused"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Border>

                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

这里只给出了一个 ContentPresenter。我想在鼠标悬停后更改渐变。我还想缩放项目的大小。我怎么做?

提前致谢 :)

4

1 回答 1

0

在 WPF 中使用状态时,您必须在所需状态内定义 Storyboard 并将更改作为动画。例如,如果您想更改项目容器的某些属性,则在 Borders 样式内的 IsMouseOver 属性上使用Trigger可能会更简单。

于 2011-10-31T08:24:59.987 回答