• 2018-8-10-WPF-鼠标移动到列表上-显示列表图标


    title author date CreateTime categories
    WPF 鼠标移动到列表上 显示列表图标
    lindexi
    2018-08-10 19:16:51 +0800
    2018-2-13 17:23:3 +0800
    WPF

    在列表新建一个图标,添加 Visibility

    Visibility="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}, Path=IsMouseOver, Converter={StaticResource BooleanToVisibilityConverter}}"

    我这里用的是 TextBlock ,鼠标移动就会显示

            <ListView AlternationCount="10">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="20"></ColumnDefinition>
                                <ColumnDefinition Width="Auto"></ColumnDefinition>
                                <ColumnDefinition ></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}, Path=(ItemsControl.AlternationIndex),Mode=OneWay,Converter={StaticResource NumberAddOne}}"></TextBlock>
                            <TextBlock Grid.Column="1" Text="点击"
                                       Visibility="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}, Path=IsMouseOver, Converter={StaticResource BooleanToVisibilityConverter}}"></TextBlock>
                            <TextBlock Grid.Column="2" Text="lindexi"></TextBlock>
                        </Grid>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

    获取当前列表项,使用{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}, Path=(ItemsControl.AlternationIndex),Mode=OneWay,Converter={StaticResource NumberAddOne}}。注意 AlternationCount 如果没设不会显示

            <ListView AlternationCount="10">
                <ListViewItem>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="20"></ColumnDefinition>
                            <ColumnDefinition ></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}, Path=(ItemsControl.AlternationIndex),Mode=OneWay,Converter={StaticResource NumberAddOne}}"></TextBlock>
                        <TextBlock Grid.Column="1" Text="lindexi"></TextBlock>
                    </Grid>
                </ListViewItem>
            </ListView>
    
        public class NumberAddOne : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                var index = (int)value;
                return index + 1;
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                throw new NotImplementedException();
            }
        }

    为何添加上面转化,这个程序员和客户对于数组的开始是不同的。

  • 相关阅读:
    6.66 分钟,一文Python爬虫解疑大全教入门!
    十分钟快速入门 Python,看完即会,不用收藏!
    Python3中真真假假True、False、None等含义详解
    Python基础系列讲解——时间模块详解大全之time模块
    超详细Pycharm部署项目视频教程
    Python进阶量化交易专栏场外篇7- 装饰器计算代码时间
    docker 基本命令
    Linux常用命令
    Docker-部署Mysql
    docker 容器内运行vim命令
  • 原文地址:https://www.cnblogs.com/lindexi/p/12085760.html
Copyright © 2020-2023  润新知