zoukankan      html  css  js  c++  java
  • 潜移默化学会WPF(样式篇)ListBox的Item样式

    <ListBox>
            <!-- 数据 -->
            <ListBoxItem>AAAA</ListBoxItem>
            <ListBoxItem>BB</ListBoxItem>
            <ListBoxItem>CCCC</ListBoxItem>
           
            <!-- 设置ListBoxItem样式 -->
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <!-- 设置控件模板 -->
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ListBoxItem">
                                <Border Background="{TemplateBinding Background}">
                                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                     VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                     TextBlock.Foreground="{TemplateBinding Foreground}"/>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                   
                    <!-- 设置触发器 -->
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="true">
                            <Setter Property="Background" Value="Black"/>
                            <Setter Property="Foreground" Value="White"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Background" Value="LightGreen"/>
                            <Setter Property="Foreground" Value="Red"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </ListBox.ItemContainerStyle>
        </ListBox>

    鼠标移上去单击  移上的颜色改变

  • 相关阅读:
    12-转盘
    11-UIView与核心动画对比
    10-动画组
    09-转场动画
    08-图片抖动(帧动画)
    07-心跳效果
    06-CABasicAnimation基础核心动画
    05-时钟效果
    计时器延迟 NSTimer和CADisplaylink GCD中的延迟
    ScrollView与UIPageController
  • 原文地址:https://www.cnblogs.com/AaronYang/p/2441640.html
Copyright © 2011-2022 走看看