zoukankan      html  css  js  c++  java
  • WPF中ListBox的使用注意事项

    1.style

    注意绿色标注处,如果想要在Listbox外使用滚动条,此处则要注销ScrollViewer,否则在界面区域只能显示ListBox时会出现点击一下,弹到顶端的问题。

     <Grid.Resources>
                <!--SelectedItem with focus -->
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FAE388" Opacity="1"/>
                <!--SelectedItem without focus-->
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="LightBlue" Opacity="0.4"/>
                <Style TargetType="ListBoxItem">
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <!--<Setter Property="Opacity" Value="0.8"/>-->
                            <Setter Property="Background" Value="#F0F0F0"/>
                            <Setter Property="Foreground" Value="Black"/>
                        </Trigger>
                        <Trigger Property="IsFocused" Value="true">
                            <Setter Property="Background" Value="Coral"/>
                            <Setter Property="Foreground" Value="Black"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
                <Style TargetType="{x:Type ListBox}">
                    <Setter Property="ItemTemplate">
                        <Setter.Value>
                            <DataTemplate DataType="{x:Type baseModel:FlowTempleteModel}">
                                <Grid Margin="10,0,5,0">
                                 
                                </Grid>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                    <!-- 定义子元素的布局容器, 比如:横向,纵向-->
                    <Setter Property="ItemsPanel">
                        <Setter.Value>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                            </ItemsPanelTemplate>
                        </Setter.Value>
                    </Setter>
                    <!-- 定义ListBox自身外观, 比如: 圆角边框-->
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ListBox">
                                <Border CornerRadius="5" Background="{TemplateBinding ListBox.Background}">
                                    <!--<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">-->
                                    <ItemsPresenter>
                                    </ItemsPresenter>
                                    <!--</ScrollViewer>-->
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Grid.Resources>
    

      

  • 相关阅读:
    java web 工程更改名字
    [转]Eclipse下开发Struts奇怪异常:org.apache.struts.taglib.bean.CookieTei
    【转】myeclipse 自定义视图Customize Perspective 没有反应
    latex建立参考文献的超链接
    latex 脚注编号也成为超链接
    自定义标签TLD文件中,rtexprvalue子标签的意思
    设计模式观察者
    设计模式模板方法
    设计模式策略
    设计模式享元
  • 原文地址:https://www.cnblogs.com/mamaxiaoling/p/14429288.html
Copyright © 2011-2022 走看看