Reputation: 1
I have window with SizeToContent = "WidthAndHeight",startup location sets to manual. This window contains one grid with two rows: first with height "1*" and second with auto height. The first row contains xamdatagrid (infragistics) and the second contains OkCancel buttons.
after xamdatagrid initialization the window is been vertically stretched beyond visible area.
I don't want to bind max height to some calculation based on system parameters and other constants.
code:
<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>
Thanks,
Zehavit
Upvotes: 0
Views: 2361
Reputation: 8803
Don't use
SizeToContent="WidthAndHeight"
alone cause it will set the size
of Window
as its content. And your XamDataGrid
has many records
so Window
will grow to a very large size. instead just delete that property then the content
will be adjusted according to Window
.
Or
give your Window
some Height
first (as try binding
the Height
of your Window
to System.Windows.SystemParameters.PrimaryScreenHeight
) then you can use SizeToContent
and Window
will not grow indefinitely.
Also Grid
row heights are irrelevant cause you have not given any fixed Height
to any control
or Grid
.
This solves the problem.
Upvotes: 0
Reputation: 285
First of all, the value 1* doesn't mean anything with the SizeToContent = "WidthAndHeight". If you change the "1*" to "Auto", you will have the same behavior. You should remove SizeToContent = "WidthAndHeight" and do this :
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="3*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Grid>
your list ..
</Grid>
<Grid Grid.Row="1">
you buttons ..
</Grid>
</Grid>
Your first row (list) will be (3/(3+1))% of the window size
The second (1/(3+1))%.
Upvotes: 0