Wpf 如何隐藏数据网格中的最后一条水平线? 使用System.Collections.Generic; 使用System.Windows; 使用System.Windows.Media; 命名空间合并网格测试 { /// ///test1window.xaml的交互逻辑 /// 公共部分类test1window:Window { DrawingVisual dv=新DrawingVisual(); 公共测试1窗口() { 初始化组件(); } 已加载私有无效窗口(对象发送器、路由目标) { var医生=新名单() { 新医生(){Name=“Zhang”,分数=15,地址=“成都”,科室=“内科”}, 新医生(){Name=“Zhang”,分数=18,地址=“成都”,科室=“内科”}, 新医生(){Name=“Zhang”,分数=17,地址=“成都”,科室=“内科”}, 新医生(){Name=“Liu”,分数=15,地址=“成都”,Dept=“Thke”}, 新医生(){Name=“Liu”,分数=18,地址=“绵阳”,Dept=“Thke”}, 新医生(){Name=“Liu”,分数=17,地址=“绵阳”,科室=“Thke”} }; TestGrid.ItemsSource=医生; } } 班主任 { 公共字符串名称{get;set;} 公共整数分数{get;set;} 公共字符串地址{get;set;} 公共字符串Dept{get;set;} } }
() 如图所示,我不想在这个数据网格中的行下显示最后一行(最后一条红线),但其他水平线显示正常,如何做Wpf 如何隐藏数据网格中的最后一条水平线? 使用System.Collections.Generic; 使用System.Windows; 使用System.Windows.Media; 命名空间合并网格测试 { /// ///test1window.xaml的交互逻辑 /// 公共部分类test1window:Window { DrawingVisual dv=新DrawingVisual(); 公共测试1窗口() { 初始化组件(); } 已加载私有无效窗口(对象发送器、路由目标) { var医生=新名单() { 新医生(){Name=“Zhang”,分数=15,地址=“成都”,科室=“内科”}, 新医生(){Name=“Zhang”,分数=18,地址=“成都”,科室=“内科”}, 新医生(){Name=“Zhang”,分数=17,地址=“成都”,科室=“内科”}, 新医生(){Name=“Liu”,分数=15,地址=“成都”,Dept=“Thke”}, 新医生(){Name=“Liu”,分数=18,地址=“绵阳”,Dept=“Thke”}, 新医生(){Name=“Liu”,分数=17,地址=“绵阳”,科室=“Thke”} }; TestGrid.ItemsSource=医生; } } 班主任 { 公共字符串名称{get;set;} 公共整数分数{get;set;} 公共字符串地址{get;set;} 公共字符串Dept{get;set;} } },wpf,Wpf,() 如图所示,我不想在这个数据网格中的行下显示最后一行(最后一条红线),但其他水平线显示正常,如何做 数据网格的线条设置适用于所有线条,因此我无法仅在最后一行设置线条视觉样式。作为一种快速技巧,您可以始终使用Snoop(或最新版本的VS中的视觉检查器)找出如何引用最后一行并使用反射覆盖它。我不知道为什么这个问题被否决-4+2,因为我认为这是一个关于WPF的好问题,因为WPF没有CSS的:类型的last或:last child选择器。如果你是对这个问题投了否决票的人,请发表评论回复,解释你为什么
数据网格的线条设置适用于所有线条,因此我无法仅在最后一行设置线条视觉样式。作为一种快速技巧,您可以始终使用Snoop(或最新版本的VS中的视觉检查器)找出如何引用最后一行并使用反射覆盖它。我不知道为什么这个问题被否决-4+2,因为我认为这是一个关于WPF的好问题,因为WPF没有CSS的
:类型的last
或:last child
选择器。如果你是对这个问题投了否决票的人,请发表评论回复,解释你为什么投了否决票。在WPF中,你通常会看到来自绑定到控件的源代码的数据。从源中删除数据,您将不会在控件中看到这些数据。
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
namespace MergeGridTest
{
/// <summary>
/// test1window.xaml 的交互逻辑
/// </summary>
public partial class test1window : Window
{
DrawingVisual dv = new DrawingVisual();
public test1window()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var Doctors = new List<Doctor>()
{
new Doctor(){Name="Zhang",Score=15,Address="Chengdu",Dept="Neike"},
new Doctor(){Name="Zhang",Score=18,Address="Chengdu",Dept="Neike"},
new Doctor(){Name="Zhang",Score=17,Address="Chengdu",Dept="Neike"},
new Doctor(){Name="Liu",Score=15,Address="Chengdu",Dept="Thke" },
new Doctor(){Name="Liu",Score=18,Address="MianYang",Dept="Thke"},
new Doctor(){Name="Liu",Score=17,Address="MianYang",Dept="Thke"}
};
TestGrid.ItemsSource = Doctors;
}
}
class Doctor
{
public string Name { get; set; }
public int Score { get; set; }
public string Address { get; set; }
public string Dept { get; set; }
}
}
<Window
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:MergeGridTest"
xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero2" x:Class="MergeGridTest.test1window"
mc:Ignorable="d"
Title="test1window" Height="450" Width="800" Loaded="Window_Loaded">
<Grid>
<DataGrid Background="LightBlue" x:Name="TestGrid" AutoGenerateColumns="False" Margin="50" IsReadOnly="True"
CanUserAddRows="False" ItemsSource="{Binding}"
RowHeight="30" HorizontalGridLinesBrush="#FFCB0202" VerticalGridLinesBrush="{x:Null}" VerticalContentAlignment="Center">
<DataGrid.Columns>
<DataGridTextColumn Header="Address" Binding="{Binding Name}" Width="*"/>
<DataGridTextColumn Header="Score" Binding="{Binding Score}" Width="*"/>
<DataGridTextColumn Header="Address" Binding="{Binding Address}" Width="*"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>