WPF Datagrid - 不显示任何滚动条 [英] WPF Datagrid - Not showing any Scrollbar

查看:56
本文介绍了WPF Datagrid - 不显示任何滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Datagrid 在 ObservableCollection 上有一个绑定,并且在对 EF 获取的一些值进行分组后被填充.

My Datagrid has a binding on an ObservableCollection and gets filled after grouping some values fetched by EF.

我的问题是,数据网格高度超出了窗口大小.有谁知道如何解决这个问题......我几乎用谷歌搜索死了......:o

My Problem is, that the datagrid-height grows beyond the window size. Does anyone know how to get that fixed... I almost googled myself to death.. :o

<UserControl x:Class="UltranizerV2.Views.Storage.InventoryList"
             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">
    <Grid>
        <Grid.RowDefinitions>

            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="25"></RowDefinition>
        </Grid.RowDefinitions>


        <DockPanel  Grid.Row="0" >
            <DataGrid ItemsSource="{Binding PresentableInventoryItems}" VerticalAlignment="Stretch" AutoGenerateColumns="False">
            <DataGrid.Columns>
                <DataGridTextColumn Header="Produkttitel" Width="350" Binding="{ Binding ProductTitle}"/>
                <DataGridTextColumn Header="Sku" Width="100" Binding="{ Binding Sku}" />
                <DataGridTextColumn Header="Menge" Width="60"  Binding="{ Binding Quantity}" />
            </DataGrid.Columns>    
            </DataGrid>
        </DockPanel>
        <Label Grid.Row="1">Arsch</Label>
        </Grid>

</UserControl>

推荐答案

总而言之,您的控件看起来不错,这表明问题出在可视化树的某个位置.最有可能的是 InventoryList 或其父项之一,它被置于控制之下,为其子项提供无限量的增长空间,例如 StackPanelScrollViewer画布.由于 DataGrid 可以增长以容纳所有项目,因此滚动条不可见.

To sum up comments your control looks fine which would suggest that the problem is somewhere up the visual tree. Most likely InventoryList, or one of its parents, it's placed in control that gives its children infinite amount of space to grow like StackPanel, ScrollViewer or Canvas. Because of that DataGrid can grow to accommodate all item hence not scroll bar is visible.

删除该控件或将其替换为限制其子项大小的控件

Remove that control or replace it with one that limits the size of its children

这篇关于WPF Datagrid - 不显示任何滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆