为WPF的DataGrid画表格

WPF中的DataGrid实现边框的方法,我参考资料后自己画了下,一种方法是:使用Border控件,另一种就是使用Path手动画。

 

 方法一:使用Path画表格

 <Path Fill="WhiteSmoke" Stroke="Silver" StrokeThickness="1px">
            <Path.Data>
                <GeometryGroup>
                    <RectangleGeometry Rect="50,50,450,510"></RectangleGeometry>
                    <LineGeometry StartPoint="50,80"  EndPoint="500,80"></LineGeometry>
                    <LineGeometry StartPoint="50,110" EndPoint="500,110"></LineGeometry>
                    <LineGeometry StartPoint="50,140" EndPoint="500,140"></LineGeometry>
                    <LineGeometry StartPoint="50,170" EndPoint="500,170"></LineGeometry>
                    <LineGeometry StartPoint="50,200" EndPoint="500,200"></LineGeometry>
                    <LineGeometry StartPoint="50,230" EndPoint="500,230"></LineGeometry>
                    <LineGeometry StartPoint="50,260" EndPoint="500,260"></LineGeometry>
                    <LineGeometry StartPoint="50,290" EndPoint="500,290"></LineGeometry>
                    <LineGeometry StartPoint="50,320" EndPoint="500,320"></LineGeometry>
                    <LineGeometry StartPoint="50,350" EndPoint="500,350"></LineGeometry>
                    <LineGeometry StartPoint="50,380" EndPoint="500,380"></LineGeometry>
                    <LineGeometry StartPoint="50,410" EndPoint="500,410"></LineGeometry>
                    <LineGeometry StartPoint="50,440" EndPoint="500,440"></LineGeometry>
                    <LineGeometry StartPoint="50,470" EndPoint="500,470"></LineGeometry>
                    <LineGeometry StartPoint="50,500" EndPoint="500,500"></LineGeometry>
                    <LineGeometry StartPoint="50,530" EndPoint="500,530"></LineGeometry>
                    <LineGeometry StartPoint="250,50" EndPoint="250,560"></LineGeometry>
                </GeometryGroup>

            </Path.Data>
        </Path>

大致效果:

 

方法二:使用border,很多高手已经演示过了。在下只是东施效颦。

 

<Grid Grid.Column="0" Name="stat" Margin="50,50" >
            <Grid.RowDefinitions>
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="200" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
           
            <Border Grid.Row="0"  BorderThickness="1,1,1,0" Grid.Column="0"  ></Border>
            <Border Grid.Row="0"  BorderThickness="0,1,1,0" Grid.Column="1" ></Border>
           
            <Border Grid.Row="1"  BorderThickness="1,1,1,0"></Border>
            <Border Grid.Row="1"  BorderThickness="0,1,1,0" Grid.Column="1"></Border>

            <Border Grid.Row="2"  BorderThickness="1,1,1,0"></Border>
            <Border Grid.Row="2"  BorderThickness="0,1,1,0"  Grid.Column="1"></Border>

            <Border Grid.Row="3"  BorderThickness="1,1,1,0"></Border>
            <Border Grid.Row="3"  BorderThickness="0,1,1,0" Grid.Column="1"></Border>
           
            <Border Grid.Row="4"  BorderThickness="1,1,1,0"></Border>
            <Border Grid.Row="4"  BorderThickness="0,1,1,0" Grid.Column="1"></Border>
           
            <Border Grid.Row="5"  BorderThickness="1,1,1,0"></Border>
            <Border Grid.Row="5"  BorderThickness="0,1,1,0" Grid.Column="1"></Border>
           
            <Border Grid.Row="6"  BorderThickness="1,1,1,0"></Border>
            <Border Grid.Row="6"  BorderThickness="0,1,1,0" Grid.Column="1"></Border>
           
            <Border Grid.Row="7"  BorderThickness="1,1,1,0"></Border>
            <Border Grid.Row="7"  BorderThickness="0,1,1,0" Grid.Column="1"></Border>
           
            <Border Grid.Row="8"  BorderThickness="1,1,1,0"></Border>
            <Border Grid.Row="8"  BorderThickness="0,1,1,0" Grid.Column="1"></Border>
           
            <Border Grid.Row="9"  BorderThickness="1,1,1,0"></Border>
            <Border Grid.Row="9"  BorderThickness="0,1,1,0" Grid.Column="1"></Border>
           
            <Border Grid.Row="10"  BorderThickness="1,1,1,0"></Border>
            <Border Grid.Row="10"  BorderThickness="0,1,1,0" Grid.Column="1"></Border>

            <Border Grid.Row="11"  BorderThickness="1,1,1,0"></Border>
            <Border Grid.Row="11"  BorderThickness="0,1,1,0"  Grid.Column="1"></Border>
           
            <Border Grid.Row="12"  BorderThickness="1,1,1,0"></Border>
            <Border Grid.Row="12"  BorderThickness="0,1,1,0" Grid.Column="1"></Border>
           
            <Border Grid.Row="13"  BorderThickness="1,1,1,0"></Border>
            <Border Grid.Row="13"  BorderThickness="0,1,1,0" Grid.Column="1"></Border>
           
            <Border Grid.Row="14"  BorderThickness="1,1,1,0"></Border>
            <Border Grid.Row="14"  BorderThickness="0,1,1,0"  Grid.Column="1"></Border>
           
            <Border Grid.Row="15"  BorderThickness="1,1,1,0"></Border>
            <Border Grid.Row="10"  BorderThickness="0,1,1,0" Grid.Column="1" Margin="0,0,0,110"></Border>
           
            <Border Grid.Row="16"  BorderThickness="1,1,1,1"></Border>
            <Border Grid.Row="12"  BorderThickness="0,1,1,1" Grid.Column="1" Margin="0,0,0,79"></Border>

 

</Grid>

本人菜鸟级别,请大家多多指教,如有更好的方法大家多多分享。O(∩_∩)O谢谢。

转载于:https://www.cnblogs.com/Cindys/archive/2011/04/20/2022525.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值