0

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

这是我的代码:

        <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>

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

4

2 回答 2

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,并遵守附加属性编码规则。)

于 2013-07-03T06:28:02.860 回答
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>

于 2015-05-14T11:21:09.417 回答