我有一个带有数据透视控件和列表框的简单页面,但是我无法使列表框伸展以获得所有可用空间。
模板:
<phone:PhoneApplicationPage.Resources>
<converter:UserMessageConverter x:Key="MessageUserConverter" />
<DataTemplate x:Key="ItemTemplate">
<StackPanel Margin="0,0,0,30">
<TextBlock Text="{Binding Model.Text}" Style="{StaticResource PhoneTextExtraLargeStyle}" FontSize="21.333" TextWrapping="Wrap" />
<TextBlock Text="{Binding User, Converter={StaticResource MessageUserConverter}}" Margin="12,3,0,0" Style="{StaticResource PhoneTextSubtleStyle}" TextWrapping="Wrap" FontSize="18.667"/>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="WindowsPhone.Application.ViewModel.MessageListViewModel">
<ListBox ItemTemplate="{StaticResource ItemTemplate}" ItemsSource="{Binding Messages}" Background="Aqua">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ContentPresenter HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
<wi:Interaction.Triggers>
<wi:EventTrigger EventName="SelectionChanged">
<wi:InvokeCommandAction Command="{Binding MessageSelectedCommand}" CommandParameter="{Binding SelectedItem, ElementName=MessageList}" />
</wi:EventTrigger>
</wi:Interaction.Triggers>
</ListBox>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
支点:
<Grid x:Name="LayoutRoot" Background="Transparent">
<!--Pivot Control-->
<controls:Pivot Title="Messages & Responses" ItemsSource="{Binding Pages}">
<controls:Pivot.ItemTemplate>
<DataTemplate>
<helpers:DataTemplateSelector Content="{Binding}" />
</DataTemplate>
</controls:Pivot.ItemTemplate>
<controls:Pivot.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title}" />
</DataTemplate>
</controls:Pivot.HeaderTemplate>
</controls:Pivot>
</Grid>
答案 0 :(得分:0)
不是100%肯定,但尝试一下
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ContentPresenter HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
答案 1 :(得分:0)
关注this,但我认为ListBox
拉伸了整个父容器,但父容器却没有。为什么aqua box位于页面的中心而不是左侧或顶部?请尝试制作相同的应用但没有模板Pivot
,也许它会将您推向正确的方向并找到问题的位置