Code Bye

问一下WPF中 datagrid 的最外面的边框怎么删掉

<Window x:Class="datagrid边框移除测试.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:datagrid边框移除测试"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <DataGrid Grid.Row="1" Name="dgMain" AutoGenerateColumns="False" CanUserAddRows="False"  Width="450" Height="250"
                          HeadersVisibility="Column" CanUserDeleteRows="False"
                          HorizontalContentAlignment="Center"
                          Background="Transparent"
                          GridLinesVisibility="None">
            <DataGrid.ColumnHeaderStyle>
                <Style TargetType="DataGridColumnHeader">
                    <Setter Property="Background" Value="Transparent"/>
                    <Setter Property="Foreground" Value="#4D4D4D"/>
                    <Setter Property="HorizontalAlignment" Value="Stretch"/>
                    <Setter Property="HorizontalContentAlignment" Value="Center"/>
                    <!--<Setter Property="BorderBrush" Value="#D6D6D6"/>-->
                    <Setter Property="BorderThickness" Value="0 0 0 0"/>
                </Style>
            </DataGrid.ColumnHeaderStyle>
            <DataGrid.RowStyle >
                <Style TargetType="DataGridRow">
                    <!--<Setter Property="Height" Value="45"/>-->
                    <Setter Property="Margin" Value="0 5 0 5"/>
                    <Setter Property="BorderThickness" Value="0"/>
                    <Setter Property="Background" Value="Transparent"/>
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="Transparent"/>
                        </Trigger>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Background" Value="Transparent"/>
                            <!--<Setter Property="Foreground" Value="Red"/>-->
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.RowStyle>
            <DataGrid.CellStyle >
                <Style TargetType="DataGridCell">
                    <Setter Property="BorderThickness" Value="0"/>
                    <Setter Property="HorizontalContentAlignment" Value="Center"/>
                    <Style.Triggers >
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Background" Value="Transparent"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.CellStyle>
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding time}" IsReadOnly="True" Width="*" Header="设置时间">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType="TextBlock">
                            <Setter Property="TextWrapping" Value="Wrap"/>
                            <Setter Property="FontSize" Value="12"/>
                            <Setter Property="Foreground" Value="#4D4D4D"/>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
                <DataGridTemplateColumn Width="*" Header="手数"  >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding amount}" Foreground="#4D4D4D" FontSize="14" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"  Width="57" Height="27" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Width="*" Header="止损价"  >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding lossPrice}" Foreground="#4D4D4D" FontSize="12"  Width="57" Height="27" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Width="*" Header="止盈价"  >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Text="{ Binding profitPrice}" Foreground="#4D4D4D" FontSize="12" Width="57" Height="27" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Width="*" Header="操作"  IsReadOnly="True" >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="删除" Foreground="#E9544E" FontSize="12" Cursor="Hand" 
                                               HorizontalAlignment="Center" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>
using System;
using System.Data;
using System.Windows;
namespace datagrid边框移除测试
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            DataTable dt = new DataTable();
            dt.Columns.Add("amount");
            dt.Columns.Add("lossPrice");
            dt.Columns.Add("profitPrice");
            dt.Columns.Add("treatyType");
            dt.Columns.Add("stopProfitStopLossId");
            dt.Columns.Add("time");
            for (int i = 0; i < 10; i++)
            {
                DataRow dr = dt.NewRow();
                dr["amount"] = i.ToString();
                dr["lossPrice"] = 3000.ToString();
                dr["profitPrice"] = 3200.ToString();
                dr["treatyType"] = "Ag(T+D)";
                dr["stopProfitStopLossId"] = i.ToString();
                dr["time"] = DateTime.Now.ToString("yyyy -MM-dd HH:mm:ss");
                dt.Rows.Add(dr);
            }
            dgMain.ItemsSource = dt.DefaultView;
        }
    }
}


问一下怎么把datagrid最外面的边框去掉。

解决方案

40

<DataGrid BorderThickness=0/>试一下

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明问一下WPF中 datagrid 的最外面的边框怎么删掉