为什么我的 wpf 网格没有包含在其容器中?

发布于 2024-09-19 18:16:14 字数 3502 浏览 4 评论 0原文

我有一个用户控件,其中有两个控件:1) 搜索条件控件(自定义用户控件)和 2) Telerik RadGridView。

除此之外,我有一个窗口,它是我的应用程序的外壳,其中存在三个区域。当此窗口打开时,我单击一个按钮,上面提到的用户控件就会插入到其中一个区域中。现在用户控件已加载,我编辑搜索条件并单击按钮以使用大约 1,000 条记录填充我的网格。问题是网格的滚动条未启用,因为网格控件会最大化以适应经过屏幕的所有数据的大小。

正常工作的唯一方法是将网格的 Height 属性设置为绝对值,但网格的大小不会随窗口而变化。

我已经尝试了我能想到的一切:当在网格中时,我将行定义大小设置为 200*,将网格放入包装面板中,将其放入停靠面板中,将垂直对齐设置为拉伸,更改停靠栏面板到堆栈面板。

壳:

<Window x:Class="WTS.CGCApplicationInterface.CGCApplicationShellView"
         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"             
         xmlns:cal="http://www.codeplex.com/CompositeWPF"
         xmlns:inf="clr-namespace:WTS.CGCApplicationInterface.Infrastructure;assembly=WTSCGCApplicationInterface.Infrastructure"             
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300" Width="750" Height="480"
        Title="CGC Interface Window">       
<Grid> 
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="200*"/>            
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <ItemsControl cal:RegionManager.RegionName="MenuRegion" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" />
    <ItemsControl cal:RegionManager.RegionName="SwitchboardRegion" Grid.Column="0" Grid.Row="1" />
    <ItemsControl cal:RegionManager.RegionName="MainRegion" Grid.Column="1" Grid.Row="1" />                            
</Grid>

用户控制:

<UserControl x:Class="WTS.CGCApplicationInterfaceMVVM.Views.Oncor.OncorTimesheetCGC"
         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" 
         xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"   
         xmlns:wtsControls="clr-namespace:WTS.CGCApplicationInterface.UserControls;assembly=WTSCGCApplicationInterface.Infrastructure"                  
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="600" Background="Red">     
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="200*" />
    </Grid.RowDefinitions>    

        <wtsControls:CGCQueryUserControl  Grid.Row="0"/>
        <telerik:RadGridView ItemsSource="{Binding Path=Timesheets}" AutoGenerateColumns="False" Grid.Row="1"
                                 ScrollViewer.VerticalScrollBarVisibility="Visible">
            <telerik:RadGridView.Columns>
                <telerik:GridViewToggleRowDetailsColumn></telerik:GridViewToggleRowDetailsColumn>
                <telerik:GridViewDataColumn Header="MyField1" UniqueName="AssociatedObject.MyField1" IsVisible="False" />
                <telerik:GridViewDataColumn Header="MyField2" UniqueName="AssociatedObject.MyField2" IsVisible="False" />


I have a user control and within it I have two controls: 1) a search criteria control (custom user control) and 2) a Telerik RadGridView.

Apart from that I have a window that is the shell for my application and in it exists three regions. When this window opens I click a button and the user control mentioned above gets inserted into one of the regions. Now that the user control is loaded I edit my search criteria and click the button to populate my grid with around 1,000 records. The problem is that the grid's scroll bar doesn't become enabled because the grid control maximizes to fit the size of all the data which runs past the screen.

The only way this works properly is to set the Height property of the grid to an absolute value but then the grid doesn't size with the window.

I've tried everything that I can think of: When in the grid I set the row def size to 200*, I put the grid in a wrap panel, I put it in a dockpanel, set the VerticalAlignment to stretch, changed the dock panel to stack panel.

Shell:

<Window x:Class="WTS.CGCApplicationInterface.CGCApplicationShellView"
         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"             
         xmlns:cal="http://www.codeplex.com/CompositeWPF"
         xmlns:inf="clr-namespace:WTS.CGCApplicationInterface.Infrastructure;assembly=WTSCGCApplicationInterface.Infrastructure"             
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300" Width="750" Height="480"
        Title="CGC Interface Window">       
<Grid> 
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="200*"/>            
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <ItemsControl cal:RegionManager.RegionName="MenuRegion" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" />
    <ItemsControl cal:RegionManager.RegionName="SwitchboardRegion" Grid.Column="0" Grid.Row="1" />
    <ItemsControl cal:RegionManager.RegionName="MainRegion" Grid.Column="1" Grid.Row="1" />                            
</Grid>

User Control:

<UserControl x:Class="WTS.CGCApplicationInterfaceMVVM.Views.Oncor.OncorTimesheetCGC"
         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" 
         xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"   
         xmlns:wtsControls="clr-namespace:WTS.CGCApplicationInterface.UserControls;assembly=WTSCGCApplicationInterface.Infrastructure"                  
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="600" Background="Red">     
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="200*" />
    </Grid.RowDefinitions>    

        <wtsControls:CGCQueryUserControl  Grid.Row="0"/>
        <telerik:RadGridView ItemsSource="{Binding Path=Timesheets}" AutoGenerateColumns="False" Grid.Row="1"
                                 ScrollViewer.VerticalScrollBarVisibility="Visible">
            <telerik:RadGridView.Columns>
                <telerik:GridViewToggleRowDetailsColumn></telerik:GridViewToggleRowDetailsColumn>
                <telerik:GridViewDataColumn Header="MyField1" UniqueName="AssociatedObject.MyField1" IsVisible="False" />
                <telerik:GridViewDataColumn Header="MyField2" UniqueName="AssociatedObject.MyField2" IsVisible="False" />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剑心龙吟 2024-09-26 18:16:14

我希望我能因为回答自己的问题而获得积分。我确实意识到这可以被利用。也就是说,在我的 shell 中,我将 ItemsControl 区域更改为 ContentControl,并且它工作得很好。

I wish I could get points for answering my own question. I do realize that this could be taken advantage of. That said, in my shell, I changed the ItemsControl region to a ContentControl and it works perfectly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文