Art*_*lin 3 silverlight windows-phone-7 windows-phone windows-phone-8
我需要显示ListBox动态内容(所以我不知道它的高度)和Button它下面.因此用户应该能够将ListBox滚动到结束并查看按钮.
在Android中我会使用RelativeLayout和below属性为按钮或其他解决方案,但在WP我不知道如何做到这一点.
我曾经尝试过的:
1)全押 StackPanel
<StackPanel>
<ListBox />
<Button />
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为StackPanel阻止了ListBox滚动.
2)好的,让我们把ListBox放在Grid中
<StackPanel>
<Grid>
<ListBox />
</Grid>
<Button />
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
什么都没发生.
3)全部放入网格并使用Grid.Row不起作用.
4)让我们全部投入Grid并Button动态设置保证金
<Grid>
<ListBox />
<Button />
</Grid>
Run Code Online (Sandbox Code Playgroud)
好的,这是有效的,但这不是一个好的解决方案,因为我需要处理ListBox每次填充并重置按钮的余量.坏坏.
PS此外,我可以把按钮作为ListBox项目(不错,但不是很好:)
请帮帮我...
如果我理解正确,你需要一个像这样定义的简单网格:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListBox />
<Button Grid.Row="1" Height="80"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
通过将行的高度设置为"星形"并将第一行设置为"自动",ListBox将填充剩余空间,而"按钮"仅为80(您可以将其更改为您喜欢的任何内容).ListBox会自动放入零行,因为如果未明确设置,则为默认值.
如果您不希望按钮固定在页面上但使用ListBox滚动,则可以编辑ListBox模板,如下所示:
<Style x:Key="ListBoxWithButtonStyle" TargetType="ListBox">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<ScrollViewer x:Name="ScrollViewer" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" Padding="{TemplateBinding Padding}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ItemsPresenter/>
<Button Content="Touch me" Height="80" Grid.Row="1"/>
</Grid>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
然后应用于ListBox:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ListBox Style="{StaticResource ListBoxWithButtonStyle}">
</ListBox>
</Grid>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
140 次 |
| 最近记录: |