none
请问WPF中 datagrid 的最外面的边框怎样删掉 RRS feed

  • 问题

  • <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的最外面边框移除掉

    2016年10月21日 9:56

答案

全部回复

  • 参考这句

    <DataGrid x:Name="dg" DataGrid.GridLinesVisibility="None">

    来自 http://stackoverflow.com/questions/28161986/wpf-datagridcell-borderthickness-0-doesnt-work


    专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms

    2016年10月22日 2:58
  • 参考这句

    <DataGrid x:Name="dg" DataGrid.GridLinesVisibility="None">

    来自 http://stackoverflow.com/questions/28161986/wpf-datagridcell-borderthickness-0-doesnt-work


    专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms

    你好,我最开始已经这样设置了,但是还是有最外层的边框

    这是我的代码

     <DataGrid Grid.Row="1" Name="dgMain" AutoGenerateColumns="False" CanUserAddRows="False"  Width="450" Height="250"
                              HeadersVisibility="Column" CanUserDeleteRows="False"
                              HorizontalContentAlignment="Center"
                              Background="Transparent"
                              GridLinesVisibility="None">
    这是我的结果

    

    2016年10月22日 3:25
  • <DataGrid BorderThickness=0/>
    • 已标记为答案 彭123 2016年10月24日 2:51
    2016年10月24日 2:51