DataGrid滚动不起作用

时间:2013-07-02 20:00:45

标签: c# silverlight xaml windows-phone

我有一个数据网格,使用从数据库中检索的数据填充。不幸的是,当检索到的行数超过数据网格的高度时,即使显示了两个滚动条,我也无法垂直或水平滚动。

这是我的代码:

                     

        <data:DataGrid x:Name="DataGrid_Transactions" AutoGenerateColumns="False" VerticalAlignment="Center" Height="300" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" Background="#FF0F1111" FontSize="26" Foreground="RoyalBlue" HorizontalGridLinesBrush="AliceBlue" IsReadOnly="True" VerticalGridLinesBrush="AliceBlue" AlternatingRowBackground="AliceBlue" FontFamily="Segoe WP SemiLight" RowDetailsVisibilityMode="Visible" RowBackground="AliceBlue">
            <data:DataGrid.Columns>
                <data:DataGridTextColumn Header="Transaction ID" Binding="{Binding TransactionID}" />
                <data:DataGridTextColumn Header="Vendor Username" Binding="{Binding VendorUsername}" />
                <data:DataGridTextColumn Header="Purchase Description" Binding="{Binding PurchaseDescription}" />
                <data:DataGridTextColumn Header="Total Price" Binding="{Binding TotalPrice}" />
                <data:DataGridTextColumn Header="Currency" Binding="{Binding Currency}" />
            </data:DataGrid.Columns>
        </data:DataGrid>
        <Button Content="Main Page" Height="72" HorizontalAlignment="Center" Margin="0,540,0,43" Name="Button_MainPage" VerticalAlignment="Center" Width="456" Click="Button_MainPage_Click" />
    </Grid>
</Grid>

有人可以帮帮我吗?谢谢:))

2 个答案:

答案 0 :(得分:1)

似乎附加属性不能直接用于此类型对象, 即使它适用于ListBox(http://www.silverlightshow.net/items/Tip-How-to-specify-ScrollViewer-s-attached-properties-in-XAML.aspx

你应该把它放在ScrollViewer

<ScrollViewer ...>
       content
</ScrollViewer>

http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer(v=vs.95).aspx

换句话说,看看这个附加的属性编码提示 http://www.codeproject.com/Articles/95746/Exposing-and-Binding-to-a-Silverlight-ScrollViewer

您也可以编写自己的附加属性。(您应该在依赖项对象注册时使用RegisterAttached,并遵守附加的属性编码规则。)

答案 1 :(得分:0)

我有工作代码:

<sdk:DataGrid x:Name="dgList" Margin="0" HeadersVisibility="All" AutoGenerateColumns="False" IsReadOnly="True" SelectionMode="Single" UseLayoutRounding="True" BorderThickness="1" BorderBrush="#FFA2B4D3">
<sdk:DataGrid.Columns>
    <sdk:DataGridTextColumn Binding="{Binding DOCTORNO}" Header="No" />
    <sdk:DataGridTextColumn Binding="{Binding DOCTORNAME}" Header="Ad Soyad" />
    <sdk:DataGridTextColumn Binding="{Binding UZMANLIKKODU}" Header="Branş" />
    <sdk:DataGridTextColumn Binding="{Binding BRANSAD}" Header="Branş Adı" />
</sdk:DataGrid.Columns>