我在Stackpannel和Grid中有一个Scrollviewer,就像子菜单一样。它设置的高度绑定到父菜单。
父菜单属性:
<Grid Grid.Row="1" x:Name="tooldropdown" Width="250" VerticalAlignment="Stretch" Visibility="{Binding ElementName=ButtonToolbox, Path=IsChecked, Converter={StaticResource BoolToVisConverter}, FallbackValue=Hidden}">
子菜单:
<Grid x:Name="PopupBaseMapLayers" Grid.Row="1" Height="{Binding ElementName=tooldropdown, Path=Height}" Visibility="Collapsed" Panel.ZIndex="3000" >
<Border Background="White" Width="253" >
<StackPanel>
<Grid Height="30" Background="#FFC6DFFF" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="31*" />
<ColumnDefinition Width="47*"/>
<ColumnDefinition Width="35" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0"HorizontalContentAlignment="Center" Content="Base Maps" VerticalContentAlignment="Center" Height="30" BorderBrush="#c6dfff" BorderThickness="1" FontSize="14" Foreground="#FF004FB4" Grid.ColumnSpan="2">
<Label.Background>
<SolidColorBrush Color="#FFC6DFFF"/>
</Label.Background>
</Label>
<Button Grid.Column="2" Click="ButtonBaseMapLayers_Click" Background="#FF004FB4" FontWeight="Bold" FontFamily="OCR A Extended" Foreground="White" Margin="4,3,3,2" BorderBrush="{x:Null}">X</Button>
</Grid>
<ScrollViewer VerticalScrollBarVisibility="Visible" Margin="0,0,0,200" CanContentScroll="True" Height="{Binding ElementName=tooldropdown, Path=ActualHeight}" >
<ItemsControl HorizontalAlignment="Center" ItemsSource="{Binding BaseMapLayers, ElementName=EsriControl}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:BaseMapLayer}">
<Border Background="Transparent" BorderBrush="Transparent" Margin="2" Padding="5">
<StackPanel Orientation="Horizontal">
<CheckBox VerticalAlignment="Center" IsEnabled="{Binding AddButtonEnabled}" IsChecked="{Binding IsInMenu}" Tag="{Binding}" />
<ContentPresenter ContentTemplate="{StaticResource BaseMapLayerMenuTemplate}" Width="250" />
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</StackPanel>
</Border>
</Grid>
然而我遇到的问题是,当网格的高度正确时,ScrollViewer会垂直溢出,并且不会在网格中正确嵌套。它没有视觉溢出但滚动条消失(见img)
答案 0 :(得分:0)
删除您不需要它的外部start_time
,它会将Stackpanel
扩展为无穷大
我刚看到你的编辑。怎么样:
ScrollViewer
一些注释:
<Grid x:Name="PopupBaseMapLayers" Grid.Row="1" Height="{Binding ElementName=tooldropdown, Path=ActualHeight}" Visibility="Collapsed" Panel.ZIndex="3000" >
<Border Background="White" Width="253" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30">
<RowDefinition Height="Auto">
</Grid.RowDefinitions>
<Grid Background="#FFC6DFFF" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="31*" />
<ColumnDefinition Width="47*"/>
<ColumnDefinition Width="35" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0"HorizontalContentAlignment="Center" Content="Base Maps" VerticalContentAlignment="Center" Height="30" BorderBrush="#c6dfff" BorderThickness="1" FontSize="14" Foreground="#FF004FB4" Grid.ColumnSpan="2">
<Label.Background>
<SolidColorBrush Color="#FFC6DFFF"/>
</Label.Background>
</Label>
<Button Grid.Column="2" Click="ButtonBaseMapLayers_Click" Background="#FF004FB4" FontWeight="Bold" FontFamily="OCR A Extended" Foreground="White" Margin="4,3,3,2" BorderBrush="{x:Null}">X</Button>
</Grid>
<ScrollViewer VerticalScrollBarVisibility="Visible" CanContentScroll="True" Grid.Row="1">
<ItemsControl HorizontalAlignment="Center" ItemsSource="{Binding BaseMapLayers, ElementName=EsriControl}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:BaseMapLayer}">
<Border Background="Transparent" BorderBrush="Transparent" Margin="2" Padding="5">
<StackPanel Orientation="Horizontal">
<CheckBox VerticalAlignment="Center" IsEnabled="{Binding AddButtonEnabled}" IsChecked="{Binding IsInMenu}" Tag="{Binding}" />
<ContentPresenter ContentTemplate="{StaticResource BaseMapLayerMenuTemplate}" Width="250" />
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
</Border>
</Grid>
,而是Height
ActualHeight
像素网格,这些30个像素将在最后被截断,并且它不会甚至在最后你有一个30
。答案 1 :(得分:0)
ScrollViewers是一种不喜欢成为某个孩子的想法的面板,他们喜欢处于最佳状态,试试这个:
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<Grid x:Name="PopupBaseMapLayers" Grid.Row="1" Height="{Binding ElementName=tooldropdown, Path=Height}" Visibility="Collapsed" Panel.ZIndex="3000" >
<Border Background="White" Width="253" >
<StackPanel>
<Grid Height="30" Background="#FFC6DFFF" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="31*" />
<ColumnDefinition Width="47*"/>
<ColumnDefinition Width="35" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0"HorizontalContentAlignment="Center" Content="Base Maps" VerticalContentAlignment="Center" Height="30" BorderBrush="#c6dfff" BorderThickness="1" FontSize="14" Foreground="#FF004FB4" Grid.ColumnSpan="2">
<Label.Background>
<SolidColorBrush Color="#FFC6DFFF"/>
</Label.Background>
</Label>
<Button Grid.Column="2" Click="ButtonBaseMapLayers_Click" Background="#FF004FB4" FontWeight="Bold" FontFamily="OCR A Extended" Foreground="White" Margin="4,3,3,2" BorderBrush="{x:Null}">X</Button>
</Grid>
<ItemsControl HorizontalAlignment="Center" ItemsSource="{Binding BaseMapLayers, ElementName=EsriControl}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:BaseMapLayer}">
<Border Background="Transparent" BorderBrush="Transparent" Margin="2" Padding="5">
<StackPanel Orientation="Horizontal">
<CheckBox VerticalAlignment="Center" IsEnabled="{Binding AddButtonEnabled}" IsChecked="{Binding IsInMenu}" Tag="{Binding}" />
<ContentPresenter ContentTemplate="{StaticResource BaseMapLayerMenuTemplate}" Width="250" />
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Border>
</Grid>
</ScrollViewer>
答案 2 :(得分:0)
修复了,似乎我把它分成两个不同的边框容器并切掉其中一个StackPannels,它的功能和滚动视图都没有溢出。这是结构变化的快速框架:
<Grid x:Name="PopupBaseMapLayers" Grid.Row="1" Panel.ZIndex="3000" VerticalAlignment="Stretch">
<Border Background="White" Width="253" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid Background="#FFC6DFFF" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="31*" />
<ColumnDefinition Width="47*"/>
<ColumnDefinition Width="35" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" HorizontalContentAlignment="Center" Content="Base Maps" VerticalContentAlignment="Center" Height="30" BorderBrush="#c6dfff" BorderThickness="1" FontSize="14" Foreground="#FF004FB4" Grid.ColumnSpan="2">
<Label.Background>
<SolidColorBrush Color="#FFC6DFFF"/>
</Label.Background>
</Label>
<Button Grid.Column="2" Background="#FF004FB4" FontWeight="Bold" FontFamily="OCR A Extended" Foreground="White" Margin="4,3,3,2" BorderBrush="{x:Null}">X</Button>
</Grid>
</Grid>
</Border>
<Border Background="White" Width="253" Margin="0,30,0,0" >
<ScrollViewer VerticalScrollBarVisibility="Visible" CanContentScroll="True" >
<StackPanel Orientation="Vertical">
<TextBlock>test data</TextBlock>
</StackPanel>
</ScrollViewer>
</Border>
</Grid>