开发者

Why is there nothing defined in ItemContainerStyle states in WPF listbox?

When I edit template and go into ItemContainerStyle template, the states are defined like Unselected, Selected, MouseOver etc. But nothing is actually done on those states. Is this behavior normal? I've worked with Silverlight Listbox. In it, the ItemContainerStyle does define all the states and many properties are changed. WPF listbox is little confusing. See this is the xaml when I edit ItemContainerStyle:

<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 Horizont开发者_高级运维alAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Border>

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

There is just a ContentPresenter given here. I want to change the Gradient when the mouse over is done. I also want to Scale the size of the item. How do I do that?

Thanks in advance :)


When using states in WPF you`ll have to define a Storyboard inside required state and make changes as Animation. If you want to change some properies of item container it may be simpler to use Trigger on IsMouseOver property inside the Borders style, for example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜