水平滚动条不起作用Datagrid

时间:2014-02-19 14:06:54

标签: c# wpf datagrid scrollbar

对于我在我的应用程序中使用的所有其他Datagrids正常工作但由于某种原因,这个没有。

我希望我的Datagrid水平滚动条在数据变大时显示,但它只是扩展整个Datagrid。

我只需要显示水平滚动条,这些是我为使其工作所做的一些事情。

<DataGrid x:Name="dgAllocate" VerticalAlignment="Stretch" HorizontalScrollBarVisibility="Auto" ItemsSource="{Binding}" Foreground="white" BorderBrush="Black" CanUserResizeRows="False" ScrollViewer.CanContentScroll="True" RowHeaderWidth="0" RowHeight="25" AutoGenerateColumns="False" TextBlock.TextAlignment="Center" Margin="26,84,687,91" Style="{x:Null}" Background="#FF616972" FontFamily="Malgun Gothic" AlternationCount="2" GridLinesVisibility="None" CanUserAddRows="False" FontSize="10">

可以回顾一下XAML并告诉我我做错了什么。

<Page x:Class="Freeway_Audit_Application.AllocateAudits"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  mc:Ignorable="d" 
  d:DesignHeight="820" d:DesignWidth="1245"
Title="AllocateAudits">
<Grid Background="White">
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>

    <!--Title of the datagrid-->
    <Label Content="Select Your Transaction" HorizontalAlignment="Left" Margin="20,58,0,0" VerticalAlignment="Top" FontFamily="Malgun Gothic" FontSize="15" Foreground="Black" Width="321"/>

    <!--Title of the invisable datagrid-->
    <Label Content="Users To-Do-List" HorizontalAlignment="Left" Margin="702,60,0,0" VerticalAlignment="Top" FontFamily="Malgun Gothic" FontSize="15" Foreground="Black" Width="216"/>


<DataGrid x:Name="dgAllocate" VerticalAlignment="Stretch" HorizontalScrollBarVisibility="T" ItemsSource="{Binding}" Foreground="white" BorderBrush="Black" CanUserResizeRows="False" ScrollViewer.CanContentScroll="True" RowHeaderWidth="0" RowHeight="25" AutoGenerateColumns="False" TextBlock.TextAlignment="Center" Margin="26,84,687,91" Style="{x:Null}" Background="#FF616972" FontFamily="Malgun Gothic" AlternationCount="2" GridLinesVisibility="None" CanUserAddRows="False" FontSize="10">
        <DataGrid.RowStyle>
            <Style TargetType="{x:Type DataGridRow}">
                <Style.Triggers>
                    <Trigger Property="AlternationIndex" Value="0">
                        <Setter Property="Background" Value="#FF616972" />
                    </Trigger>
                    <Trigger Property="AlternationIndex" Value="1">
                        <Setter Property="Background" Value="#FF585F66" />
                    </Trigger>
                    <DataTrigger Binding="{Binding Selectable}" Value="False">
                        <Setter Property="Background" Value="LightGray" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </DataGrid.RowStyle>
        <DataGrid.ColumnHeaderStyle>
            <Style TargetType="{x:Type DataGridColumnHeader}">
                <Setter Property="HorizontalContentAlignment" Value="Center"/>
                <Setter Property="BorderBrush" Value="Black"/>
                <Setter Property="FontWeight" Value="Bold"/>
                <Setter Property="FontSize" Value="10"/>
                <Setter Property="Background">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0,0" StartPoint="0,1">
                            <GradientStop Color="#FF4B525A" Offset="1.0"/>
                            <GradientStop Color="#FF343841" Offset="0.0"/>
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Foreground" Value="White"/>
            </Style>
        </DataGrid.ColumnHeaderStyle>
        <DataGrid.Columns>
            <DataGridTextColumn Binding="{Binding AAAA}" ClipboardContentBinding="{x:Null}" Header="AAAA" Width="*" Visibility="Hidden"/>
            <DataGridTextColumn Binding="{Binding BBBB}" ClipboardContentBinding="{x:Null}" Header="BBBB" Width="*" Visibility="Hidden"/>
            <DataGridTextColumn Binding="{Binding CCCC}" ClipboardContentBinding="{x:Null}" Header="CCCC" Width="*" Visibility="Hidden"/>
            <DataGridTextColumn Binding="{Binding DDDD}" ClipboardContentBinding="{x:Null}" Header="DDDD " Width="*"/>
            <DataGridTextColumn Binding="{Binding EEEE}" ClipboardContentBinding="{x:Null}" Header="EEEE" Width="*"/>
            <DataGridTextColumn Binding="{Binding FFFF}" ClipboardContentBinding="{x:Null}" Header="FFFF" Width="*"/>
            <DataGridTextColumn Binding="{Binding GGGG}" ClipboardContentBinding="{x:Null}" Header="GGGG" Width="*"/>
            <DataGridTextColumn Binding="{Binding HHHH}" ClipboardContentBinding="{x:Null}" Header="HHHH" Width="*"/>
            <DataGridTextColumn Binding="{Binding IIII}" ClipboardContentBinding="{x:Null}" Header="IIII" Width="*" Visibility="Hidden"/>
            <DataGridTextColumn Binding="{Binding JJJJ}" ClipboardContentBinding="{x:Null}" Header="JJJJ" Width="*"/>
            <DataGridTextColumn Binding="{Binding KKKK}" ClipboardContentBinding="{x:Null}" Header="KKKK" Width="*" Visibility="Hidden"/>
            <DataGridTextColumn Binding="{Binding LLLL}" ClipboardContentBinding="{x:Null}" Header="LLLL" Visibility="Hidden" Width="*"/>
        </DataGrid.Columns>
    </DataGrid>

2 个答案:

答案 0 :(得分:2)

HorizontalScrollBarVisibility="Auto" 而不是这个尝试 HorizontalScrollBarVisibility="Visible"

答案 1 :(得分:0)

你能分享更多的XAML吗?我想知道你的Datagrid是不是包含在子网格中并因此自动扩展,因为它链接到允许自动重新调整大小的网格(或其他东西)(基本上自动填充到窗口,因为它没有被锁定)