我的DataGrid显示在可视范围之外的数据。我已经在StackOverflow上查看了几个类似的问题,但它们似乎都没有解决我的问题。我无法弄清楚我做错了什么。这就是我的xaml的样子:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock HorizontalAlignment="Left" Foreground="{DynamicResource TitleFontColor}"
TextWrapping="Wrap" Text="{Binding WindowTitle}" VerticalAlignment="Center"
Margin="10,10,0,10" FontSize="18.667" FontFamily="Segoe UI" />
<Border Background="{DynamicResource pnlworkarea}"
Grid.Row="1" CornerRadius="2" BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="65"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border BorderThickness="1"
Background="{DynamicResource Brush_HeaderNew}"
BorderBrush="{DynamicResource pnlworkareastroke}"
CornerRadius="2" Margin="5">
<Grid Margin="0">
<ListBox ItemsSource="{Binding ViewMenuItems}" SelectedItem="{Binding Viewselected}"
VerticalAlignment="Center" Style="{DynamicResource Content_Header_ListBoxStyle}"
ItemTemplate="{DynamicResource Header_DataTemplate}"
ItemContainerStyle="{DynamicResource ContentHeader_ListBoxItemStyle}"
ItemsPanel="{DynamicResource Header_ItemsPanelTemplate}" HorizontalAlignment="Left"/>
</Grid>
</Border>
<Grid Grid.Row="1" Margin="5">
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Top" Margin="10,0,0,0">
<ContentControl Focusable="False" Content="ContentControl"
Background="{DynamicResource Brush_VectorIcon}"
Template="{DynamicResource vector_Summary}"
Height="16" Margin="0,5,0,0"/>
<TextBlock TextWrapping="Wrap" Text="{Binding SearchDisplayMessage}" Margin="5,3,0,0" VerticalAlignment="Center"/>
</StackPanel>
</Grid>
<Grid Grid.Row="2" Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<DataGrid x:Name="dataGrid"
commands:ControlEvents.GridViewSelectionChangedEventCommand="{Binding SelectionItemsChangeCommand}"
SelectionMode="Single"
AutoGenerateColumns="True"
Margin="0,5" Grid.Row="1" IsReadOnly="True"
ItemsSource="{Binding GridItem, Mode=TwoWay}" SelectedItem="{Binding SelectedItem}"
AlternatingRowBackground="#FFF5F4F8" Background="White" Grid.ColumnSpan="2"
ScrollViewer.CanContentScroll="True"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto">
<i:Interaction.Behaviors>
<Behaviors:SelectorDoubleClickCommandBehavior Command="{Binding GridDoubleclickcommand}"/>
</i:Interaction.Behaviors>
</DataGrid>
</Grid>
</Grid>
</Border>
</Grid>
只是添加这里的DataGrid不是我正在使用的实际DataGrid。我的自定义DataGrid派生自DataGrid。但我也尝试使用普通的DataGrid,但似乎也没有用。
答案 0 :(得分:4)
我有一个类似的问题,水平滚动条没有显示。我有一个宽度为“*”的列。删除后,滚动条出现了。我想如果你将宽度设置为固定,它也会出现。
答案 1 :(得分:2)
你的身高是自动
<Grid Grid.Row="2" Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<DataGrid x:Name="dataGrid"
SelectionMode="Single"
AutoGenerateColumns="True"
Margin="0,5" Grid.Row="1" IsReadOnly="True"
ItemsSource="{Binding GridItem, Mode=TwoWay}" SelectedItem="{Binding SelectedItem}"
AlternatingRowBackground="#FFF5F4F8" Background="White" Grid.ColumnSpan="2"
ScrollViewer.CanContentScroll="True"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto">
</DataGrid>
</Grid>
更改为
<DataGrid Grid.Row="2" x:Name="dataGrid"
SelectionMode="Single"
AutoGenerateColumns="True"
Margin="0,5" Grid.Row="1" IsReadOnly="True"
ItemsSource="{Binding GridItem, Mode=TwoWay}" SelectedItem="{Binding SelectedItem}"
AlternatingRowBackground="#FFF5F4F8" Background="White" Grid.ColumnSpan="2"
ScrollViewer.CanContentScroll="True"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto">
</DataGrid>
答案 2 :(得分:1)
我无法猜测你做错了什么,因为代码中最大规模的多边形版本向我显示水平滚动条...
<UserControl.Resources>
<x:ArrayExtension x:Key="MyArray" Type="{x:Type TextBlock}">
<TextBlock Name="Test1" Text="12345678"
DataContext="12345678" Tag="12345689"/>
<TextBlock Name="Test2" Text="12345678"
DataContext="12345678" Tag="12345689"/>
<TextBlock Name="Test1" Text="12345678"
DataContext="12345678" Tag="12345689"/>
<TextBlock Name="Test2" Text="12345678"
DataContext="12345678" Tag="12345689"/>
<TextBlock Name="Test1" Text="12345678"
DataContext="12345678" Tag="12345689"/>
<TextBlock Name="Test2" Text="12345678"
DataContext="12345678" Tag="12345689"/>
<TextBlock Name="Test1" Text="12345678"
DataContext="12345678" Tag="12345689"/>
<TextBlock Name="Test2" Text="12345678"
DataContext="12345678" Tag="12345689"/>
<TextBlock Name="Test1" Text="12345678"
DataContext="12345678" Tag="12345689"/>
<TextBlock Name="Test2" Text="12345678"
DataContext="12345678" Tag="12345689"/>
<TextBlock Name="Test1" Text="12345678"
DataContext="12345678" Tag="12345689"/>
<TextBlock Name="Test2" Text="12345678"
DataContext="12345678" Tag="12345689"/>
</x:ArrayExtension>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock HorizontalAlignment="Left"
TextWrapping="Wrap"
Text="My Text Clock"
VerticalAlignment="Center"
Margin="10,10,0,10" FontSize="18.667"
FontFamily="Segoe UI" />
<Border Grid.Row="1" CornerRadius="2" BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="65"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border BorderThickness="1"
CornerRadius="2" Margin="5">
<Grid Margin="0">
<ListBox
ItemsSource="{Binding
ViewMenuItems}"
VerticalAlignment="Center"
HorizontalAlignment="Left"/>
</Grid>
</Border>
<Grid Grid.Row="1" Margin="5">
<StackPanel HorizontalAlignment="Left"
Orientation="Horizontal"
VerticalAlignment="Top" Margin="10,0,0,0">
<ContentControl Focusable="False"
Content="ContentControl"
Height="16" Margin="0,5,0,0"/>
<TextBlock TextWrapping="Wrap"
Text="DisplayHerePlz!"
Margin="5,3,0,0"
VerticalAlignment="Center"/>
</StackPanel>
</Grid>
<Grid Grid.Row="2" Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<tk:DataGrid x:Name="dataGrid"
SelectionMode="Single"
AutoGenerateColumns="True"
Margin="0,5" Grid.Row="1"
IsReadOnly="True"
ItemsSource="{StaticResource MyArray}"
ScrollViewer.CanContentScroll="True"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"
AlternatingRowBackground="#FFF5F4F8"
Background="White"
Grid.ColumnSpan="2">
</tk:DataGrid>
</Grid>
</Grid>
</Border>
</Grid>
它可能是我省略的其他位,这可能导致水平宽度超出滚动视图...
答案 3 :(得分:1)
在这里,您应该记住几件事情,分配datagridview的width属性。定义列,将最后一列的宽度设置为auto,并指定一些minWidth。
<DataGrid VerticalAlignment="Top" Margin="0,0,0,0" Height="221" HorizontalAlignment="Left" Width="234"
DataContext="{DynamicResource ItemCollectionViewSource}"
ItemsSource="{Binding}" AutoGenerateColumns="False" IsReadOnly="True"
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Auto" >
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding ID}" Header="ID"/>
<DataGridTextColumn Binding="{Binding URL}" Header="URL" Width="Auto" MinWidth="186"/>
</DataGrid.Columns>
</DataGrid>