When I run the following Northwind WPF Toolkit Datagrid code from this article, I get a datagrid, but there are no scrollbars and hence the user can only see part of the datagrid. I am using the newest version March 2009.
What do I need to specify so that the WPF Datagrid has scrollbars?
I tried putting the datagrid in a ScrollViewer but that didn't help.
XAML:
<Window x:Class="TestDataGrid566.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit" Title="Window1" Height="600" Width="800"> <StackPanel> <toolkit:DataGrid x:Name="TheDataGrid" AutoGenerateColumns="True"/> </StackPanel> </Window>
code-behind:
using System.Linq; using System.Windows; using TestDataGrid566.Model; namespace TestDataGrid566 { public partial class Window1 : Window { public Window1() { InitializeComponent(); NorthwindDataContext db = new NorthwindDataContext(); var customers = from c in db.Customers select c; TheDataGrid.ItemsSource = customers; } } }
There are two predefined elements that enable scrolling in WPF applications: ScrollBar and ScrollViewer. The ScrollViewer control encapsulates horizontal and vertical ScrollBar elements and a content container (such as a Panel element) in order to display other visible elements in a scrollable area.
VerticalAlignment="Stretch" ), but on the small screen, automatically display the vertical scroll bar when needed.
Place a panel in location where you want the label to be, set it's AutoScroll property to true. Then place the label in the panel, anchor it and set it's AutoSize property to true. This will make the panel provide the scroll bars if the label's text extends outside of the panel.
Put the DataGrid
in a Grid
, DockPanel
, ContentControl
or directly in the Window
. A vertically-oriented StackPanel
will give its children whatever vertical space they ask for - even if that means it is rendered out of view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With