wpf ListView上下左右滚动条取消

1.上下滚动条取消

ScrollViewer.VerticalScrollBarVisibility=“Disabled”

2.左右滚动条取消

ScrollViewer.HorizontalScrollBarVisibility=“Disabled”

3.禁止滚动

IsEnabled=“False”

4.ListView数据居中

<ListView.ItemContainerStyle>
   <Style TargetType="{x:Type ListViewItem}">
       <Setter Property="HorizontalContentAlignment" Value="Center" />
   </Style>
</ListView.ItemContainerStyle>

5.界面(红色框是里面1、2、3、4有解释)

wpf ListView上下左右滚动条取消

<Window x:Class="wpfListView滚动使用.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:wpfListView滚动使用"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800" Loaded="Window_Loaded">
    <Grid>
        <ListView x:Name="ListV" ScrollViewer.VerticalScrollBarVisibility="Disabled" FontSize="22" ScrollViewer.HorizontalScrollBarVisibility="Disabled" IsEnabled="False" Margin="10,10,332,79">
            <ListView.ItemContainerStyle>
                <Style TargetType="{x:Type ListViewItem}">
                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="编号" Width="100" DisplayMemberBinding="{Binding ID}"/>
                    <GridViewColumn Header="姓名" Width="100" DisplayMemberBinding="{Binding Name}"/>
                    <GridViewColumn Header="性别" Width="90" DisplayMemberBinding="{Binding SEX}"/>
                </GridView>
            </ListView.View>
        </ListView>

    </Grid>
</Window>

6.代码

代码图片:
wpf ListView上下左右滚动条取消
代码:

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace wpfListView滚动使用
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("ID");
        dt.Columns.Add("Name");
        dt.Columns.Add("SEX");


        for (int i = 0; i < 10; i++)
        {
            DataRow row = dt.NewRow();
            row["ID"] = i + 1;
            row["Name"] = "姓名" + i + 1;

            row["SEX"] = "男";

            dt.Rows.Add(row);
        }

        ListV.ItemsSource = dt.DefaultView;
    }
  } 
}
上一篇:靠着这份190页的面试资料,真香


下一篇:ListView缓存机制源码学习