【问题标题】:Customized Datagrid in WPFWPF 中的自定义数据网格
【发布时间】:2011-11-08 13:22:34
【问题描述】:

我是 wpf 的新手并且正在开发一个会计应用程序,我的问题是如此简单,但我很惊讶我找不到一个简单的解决方案,它是这样的:

我必须创建一个数据网格,其中只有列应该有可见的边框。我的意思是它应该看起来像这样:

 | col1 | col2| col3|

 |      |     |     |

 |      |     |     |

 |-----|------|-----|

我做了我能做的一切,但我做到了:

我不明白为什么我的垂直线没有碰到边框......

tis 是我用来生成数据网格的 xaml:

<DataGrid Grid.Row="1" AutoGenerateColumns="False" x:Name="dataGrid1" VerticalAlignment="Stretch"
        CanUserReorderColumns="False" GridLinesVisibility="None" HorizontalGridLinesBrush="White"
        VerticalGridLinesBrush="White" Background="Transparent" Foreground="White" CanUserResizeRows="False"
        BorderBrush="White" BorderThickness="2" RowBackground="#FF008284" MinRowHeight="5" FontSize="14"
        ItemsSource="{Binding  }" Margin="8" SelectionMode="Single">
    <DataGrid.Resources>
        <Style TargetType="{x:Type DataGridColumnHeader}">
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="VerticalAlignment" Value="Stretch" />
            <Setter Property="Background" Value="#FF008284" />
            <Setter Property="Foreground" Value="White" />
            <Setter Property="Visibility" Value="Visible" />
            <Setter Property="Height" Value="40" />
            <Setter Property="HorizontalAlignment" Value="Stretch" />
            <Setter Property="HorizontalContentAlignment" Value="Center" />
            <Setter Property="BorderThickness" Value="1,1,1,1" />
            <Setter Property="BorderBrush" Value="White" />
        </Style>
        <Style TargetType="{x:Type DataGridCell}">
            <Setter Property="BorderThickness" Value="1,0,1,0" />
            <Setter Property="BorderBrush" Value="White" />
            <Setter Property="TextBlock.TextAlignment" Value="Center" />
            <Setter Property="Height" Value="30" />
            <Setter Property="HorizontalContentAlignment" Value="Right" />
            <Setter Property="TextBlock.FontSize" Value="14" />
        </Style>
    </DataGrid.Resources>
    <DataGrid.Columns>
        <DataGridTextColumn Width="120*" Header="Account Head" CanUserResize="False" CanUserReorder="False"
                CanUserSort="False" Binding="{Binding Path=AC_NAME}" />
        <DataGridTextColumn Width="60*" Header="Category" CanUserResize="False" CanUserReorder="False"
                CanUserSort="False" Binding="{Binding Path=AC_CATE}" FontSize="16" />
        <DataGridTextColumn Width="80*" Header="Debit" CanUserResize="False" CanUserReorder="False" CanUserSort="False"
                Binding="{Binding Path=AC_TOT_DR}" FontSize="16" />
        <DataGridTextColumn Width="80*" Header="Credit" CanUserResize="False" CanUserReorder="False" CanUserSort="False"
                Binding="{Binding Path=AC_TOT_CR}" FontSize="16" />
    </DataGrid.Columns>
</DataGrid>

感谢您的考虑......

【问题讨论】:

    标签: .net wpf visual-studio datagrid wpfdatagrid


    【解决方案1】:

    您需要更改DataGriddefault Template,因为除了水平滚动条之外,最后一行下方没有创建任何内容。

    【讨论】:

    • 那么你是在告诉我没有简单的方法来完成这个小小的基本定制......这不是有点奇怪吗??我的意思是我认为这应该是很常见的行为...... ...
    • @Sudh:是的,这正是我要告诉你的,这并不是 WPF 第一次有什么奇怪的地方......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-11
    • 1970-01-01
    • 1970-01-01
    • 2013-05-11
    • 2017-04-14
    • 1970-01-01
    相关资源
    最近更新 更多