WPF xamdatagrid高度+窗口大小到内容

时间:2015-12-03 09:50:41

标签: c# wpf infragistics xamdatagrid sizetocontent

我有一个带有SizeToContent =“WidthAndHeight”的窗口,启动位置设置为手动。 该窗口包含一个有两行的网格:第一个高度为“1 *”,第二个高度为自动高度。 第一行包含xamdatagrid(infragistics),第二行包含OkCancel按钮。

在xamdatagrid初始化之后,窗口被垂直拉伸超出可见区域。

我不想根据系统参数和其他常量将max height绑定到某些计算。

See: Window screenshot

代码:

<Window x:Class="CopyRenameLineItems.CopyAndRename"
         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:igDP="http://infragistics.com/DataPresenter"
         x:Name="CopyWindow" Title="Copy/Rename Line Item"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="500"
         d:DataContext="{d:DesignInstance d:Type=copyRenameLineItems:CopyAndRenameViewModel}" SizeToContent="WidthAndHeight" >

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Assets.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>
<Grid Margin="7" Name="MainGrid">

    <Grid.RowDefinitions>
        <RowDefinition Height="1*"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid Grid.Row="0">
        <igDP:XamDataGrid Name="CopyRenameGrid" Margin="5" GroupByAreaLocation="None" DataSource="{Binding Rows,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                            AutoFit="True" RecordContainerGenerationMode="PreLoad" >
            <igDP:XamDataGrid.FieldSettings>
                <igDP:FieldSettings
                    CellValuePresenterStyle="{StaticResource CellsBorder}"
                    AutoSizeOptions="All"
                AllowEdit="True"   
                AllowRecordFiltering="True"
                FilterLabelIconDropDownType ="MultiSelectExcelStyle" 
                CellClickAction="EnterEditModeIfAllowed"/>
            </igDP:XamDataGrid.FieldSettings>
            <igDP:XamDataGrid.FieldLayoutSettings>
                <igDP:FieldLayoutSettings 
                    AllowClipboardOperations="All"                                
                    AutoGenerateFields="False"
                    AutoFitMode="Never"
                    FilterRecordLocation="OnTop"                                
                    FilterUIType="LabelIcons"  />
            </igDP:XamDataGrid.FieldLayoutSettings>
            <igDP:XamDataGrid.FieldLayouts>
                <igDP:FieldLayout>
                    <igDP:FieldLayout.Fields>
                        <igDP:Field Name="Copy" >
                            <igDP:Field.Settings>
                                <igDP:FieldSettings Width="Auto" LabelPresenterStyle="{StaticResource CopyHeader}" />
                            </igDP:Field.Settings>
                        </igDP:Field>
                        <igDP:Field Name="Name" Label="Name"">
                            <igDP:Field.Settings>
                                <igDP:FieldSettings AllowEdit="False" Width="Auto" />
                            </igDP:Field.Settings>
                        </igDP:Field>
                        <igDP:Field Name="Description" Label="Description">
                            <igDP:Field.Settings>
                                <igDP:FieldSettings AllowEdit="False" Width="Auto"/>
                            </igDP:Field.Settings>
                        </igDP:Field>
                        <igDP:Field Name="NewName" Label="New name" Width="200">
                        </igDP:Field>
                    </igDP:FieldLayout.Fields>
                </igDP:FieldLayout>
            </igDP:XamDataGrid.FieldLayouts>
        </igDP:XamDataGrid>

    </Grid>

    <Grid Grid.Row="1" Margin="0,7,0,0" VerticalAlignment="Bottom">
        <Grid.ColumnDefinitions >
            <ColumnDefinition Width="1*"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Grid Grid.Column="0">
            <Button Height="25" Width="45" HorizontalAlignment="Right" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" 
                    Content="OK" Command="{Binding CopyRenameWindowOkButtonClick}" CommandParameter="{Binding ElementName=CopyWindow}" Margin="0,0,15,0"/>
        </Grid>
        <Grid Grid.Column ="1">
            <Button Height="25" Width="45" HorizontalAlignment="Right" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Content="Cancel" Command="{Binding  CloseWindowCancelButtonClick}"
                CommandParameter="{Binding ElementName=CopyWindow}"/>

        </Grid>
    </Grid>


</Grid>
</Window>

谢谢,

Zehavit

2 个答案:

答案 0 :(得分:0)

首先,值1 *并不代表SizeToContent =&#34; WidthAndHeight&#34;的任何内容。如果您更改&#34; 1 *&#34;对于&#34; Auto&#34;,您将拥有相同的行为。你应该删除SizeToContent =&#34; WidthAndHeight&#34;并这样做:

<Grid >
    <Grid.RowDefinitions>
        <RowDefinition Height="3*"/>
        <RowDefinition Height="1*"/>

    </Grid.RowDefinitions>
    <Grid>
        your list ..
    </Grid>
    <Grid Grid.Row="1">
        you buttons ..
    </Grid>
</Grid>

您的第一行(列表)将是窗口大小的(3 /(3 + 1))%

第二个(1 /(3 + 1))%。

答案 1 :(得分:0)

请勿使用

  

SizeToContent = “WidthAndHeight”

单独

会导致它将size的{​​{1}}设置为其内容。而且您的Window有很多XamDataGrid,因此records会变得非常大。而只是删除该属性,然后Window将根据content进行调整。

先向Window部分Window Height binding Height {strong} <{> Window )然后您可以使用 System.Windows.SystemParameters.PrimaryScreenHeight ,而SizeToContent将无法无限增长。 Window行高也是无关紧要的,因为您未向任何GridHeight提供任何固定的control

这解决了这个问题。