• 【WPF】ListView使用汇总


    1、带有GridView的ListView样式

    https://www.cnblogs.com/king10086/p/11905494.html

    2、动态更改listview某一项的文字颜色

    https://bbs.csdn.net/topics/390859580

    https://docs.microsoft.com/zh-cn/previous-versions/ms750769(v=vs.100)?redirectedfrom=MSDN

    <Style TargetType="{x:Type ListViewItem}">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding LoginStat}" Value="登陆失败">
                                            <Setter Property="Foreground" Value="Red" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>

    3、ListView插入图片

    <ListView x:Name="TvBox" HorizontalAlignment="Stretch" VerticalAlignment="Top">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <UniformGrid Columns="5" HorizontalAlignment="Stretch"/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ListView.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Vertical" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                    <Image Source="{Binding ImageData}" HorizontalAlignment="Stretch" VerticalAlignment="Top" Stretch="UniformToFill" />
                    <TextBlock Text="{Binding Title}" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" />
                </StackPanel>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
    
            this.TvBox.ItemsSource = new MovieData[]
            {
                new MovieData{Title="Movie 1", ImageData=LoadImage("image.jpg")},
                new MovieData{Title="Movie 2", ImageData=LoadImage("image.jpg")},
                new MovieData{Title="Movie 3", ImageData=LoadImage("image.jpg")},
                new MovieData{Title="Movie 4", ImageData=LoadImage("image.jpg")},
                new MovieData{Title="Movie 5", ImageData=LoadImage("image.jpg")},
                new MovieData{Title="Movie 6", ImageData=LoadImage("image.jpg")}
            };
        }
    
        // for this code image needs to be a project resource
        private BitmapImage LoadImage(string filename)
        {
            return new BitmapImage(new Uri("pack://application:,,,/" + filename));
        }
    }
    /*******相与枕藉乎舟中,不知东方之既白*******/
  • 相关阅读:
    poj 1634
    poj 2153
    POJ 1693
    poj 1789
    POJ 2676
    vue 路由
    用 node.js 创建第一个Hello World
    js原生Ajax 的封装和原理
    BFC原理
    怎么理解js的面向对象编程
  • 原文地址:https://www.cnblogs.com/Mars-0603/p/14798726.html
Copyright © 2020-2023  润新知