在我的WPF项目中,我在Grid中有一个ItemsControl,它存在于UserControl(最终是一个Window)中。我希望窗口默认是一定的大小,并希望用户能够扩展窗口(如果他们想要的话)(因此不能强制特定的窗口大小)。
问题是,当ItemsControl被填充时,窗口将调整为最大屏幕大小。这非常令人讨厌,因为我希望它受窗口大小的限制,而不是缩放到内容大小。
我怎样才能做到这一点?
GIF演示问题:http://imgur.com/U2e7PFO
<UserControl x:Class="TribeCast.Windows.PlaylistGenerationWizard.SetupSlide.SetupSlideView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:TribeCast.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:playlistGenerationWizard="clr-namespace:TribeCast.Windows.PlaylistGenerationWizard"
d:DesignHeight="491"
d:DesignWidth="678"
mc:Ignorable="d" Width="Auto" Height="Auto" MinHeight="425" MinWidth="600">
<Grid Margin="0" Background="{DynamicResource BackgroundGrey}">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="32" />
<RowDefinition Height="32" />
<RowDefinition />
<RowDefinition Height="42" />
<RowDefinition Height="42" />
</Grid.RowDefinitions>
<Label Grid.Row="0"
Margin="6,0,0,0" Content="Playlist Setup" FontSize="18.667" Foreground="{DynamicResource TextLight}" Padding="0" VerticalAlignment="Center"/>
<TextBlock Grid.Row="1"
Margin="6,5,0,5" Foreground="{DynamicResource TextDark}"><Run Text="Please define how many duplicates of each item should appear in the playlist"/></TextBlock>
<Grid Grid.Row="2"
Margin="0" Height="30" Background="{DynamicResource RowItem}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="105" />
<ColumnDefinition Width="60" />
<ColumnDefinition Width="105" />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Margin="5,0"
Text="Broadcast Name" VerticalAlignment="Center" Foreground="{DynamicResource TextLight}" />
<TextBlock Grid.Column="1"
Margin="5,0"
Text="Original Duration" VerticalAlignment="Center" Foreground="{DynamicResource TextLight}" />
<TextBlock Grid.Column="2"
Margin="5,0"
Text="Repeat" VerticalAlignment="Center" Foreground="{DynamicResource TextLight}" />
<TextBlock Grid.Column="3"
Margin="5,0"
Text="Total Duration" VerticalAlignment="Center" Foreground="{DynamicResource TextLight}" />
</Grid>
<ScrollViewer Grid.Row="3"
VerticalScrollBarVisibility="Auto">
<ItemsControl x:Name="Items"
Margin="0" Background="{DynamicResource VeryDarkGradientIndented}" />
</ScrollViewer>
<StackPanel Grid.Row="4"
Orientation="Horizontal" Background="{DynamicResource BackgroundGrey}">
<TextBlock VerticalAlignment="Center" Margin="6,0,0,0" Foreground="{DynamicResource TextLight}"><Run Text="Genera"/><Run Text="t"/><Run Text="ed Playlist Ordering:"/></TextBlock>
<RadioButton Content="Repeated"
GroupName="GenerationAlgorithm"
IsChecked="{Binding GenerationAlgorithm, ConverterParameter={x:Static playlistGenerationWizard:GenerationAlgorithm.InPlace}, Converter={converters:EnumToBooleanConverter}}"
ToolTip="The playlist will be generated without changing the original order." VerticalAlignment="Center" Margin="6,0" />
<RadioButton Content="Evenly Distributed"
GroupName="GenerationAlgorithm"
IsChecked="{Binding GenerationAlgorithm, ConverterParameter={x:Static playlistGenerationWizard:GenerationAlgorithm.EvenlyDistributed}, Converter={converters:EnumToBooleanConverter}}"
ToolTip="The playlist will be generated by evenly distributing each item. Where possible, no broadcasts will play back to back." VerticalAlignment="Center" Padding="0" Margin="6,0" Cursor="" />
<RadioButton Content="Random"
GroupName="GenerationAlgorithm"
IsChecked="{Binding GenerationAlgorithm, ConverterParameter={x:Static playlistGenerationWizard:GenerationAlgorithm.Random}, Converter={converters:EnumToBooleanConverter}}"
ToolTip="The playlist will be generated in a completely random order with no guarantees about back to back play." VerticalAlignment="Center" Margin="6,0" />
</StackPanel>
<DockPanel Margin="0" Grid.Row="5" Background="{DynamicResource TransparentWhite}">
<TextBlock
Text="{Binding TotalDuration, StringFormat='Total Duration: \{0\} '}" HorizontalAlignment="Left" Width="300" Height="42" d:LayoutOverrides="LeftPosition, RightPosition" Margin="6,0,0,0" />
<TextBlock
Text="{Binding TotalItems, StringFormat='Items: \{0\} '}" Height="42" Margin="0,0,6,0" Width="300" DockPanel.Dock="Right" HorizontalAlignment="Right" FlowDirection="RightToLeft" ToolTip="Original number of items to duplicate" />
</DockPanel>
</Grid>
答案 0 :(得分:0)
尝试将ScrollViewer
的{{1}}绑定到其父Height
。例如:
ActualHeight
编辑:实际上,这可能不是你的情况,因为你在视图中有多个控件。
您是否尝试将相应<ScrollViewer Grid.Row="3"
Height={Binding ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Grid}}
VerticalScrollBarVisibility="Auto">
<ItemsControl x:Name="Items" Margin="0" Background="{DynamicResource VeryDarkGradientIndented}" />
</ScrollViewer>
的{{1}}设置为Height
?
RowDefinition