<Grid Name="FavouriteStations" Visibility="Visible" >
<ListBox Name="FavouriteStationsListBox" ItemsSource="{Binding}" Loaded="FavouriteStationsListBoxLoaded" >
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<local:StationTemplateSelector Content="{Binding}">
<local:StationTemplateSelector.St>
<DataTemplate>
<Grid MinHeight="150" MinWidth="480" Background="#242224" >
</Grid>
</DataTemplate>
</local:StationTemplateSelector.St>
<local:StationTemplateSelector.Ad>
<DataTemplate>
<Grid MinHeight="150" MinWidth="480" Background="#FFFFFF" >
</Grid>
</DataTemplate>
</local:StationTemplateSelector.Ad>
</local:StationTemplateSelector>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
我有一个listbox
有多个数据模板。纵向方向很好,但当我将其更改为横向时,listboxitem
高度自动设置为MinHeight
,宽度设置为{ {1}}但我希望宽度与我尝试以下的屏幕宽度相同
MinWidth
但<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListBox.ItemContainerStyle>
具有相同的宽度和高度,唯一的区别是我看到它与屏幕中心对齐。我该如何解决这个问题?
答案 0 :(得分:0)
好的,我找到了解决方案。该问题是由DataTemplateSelector
引起的,您必须在Template
部分中为DataTemplateSelector
(StationTemplateSelector)设置<phone:PhoneApplicationPage.Resources>
值才能使其生效。< / p>
<phone:PhoneApplicationPage.Resources>
<Style TargetType="local:StationTemplateSelector">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:StationTemplateSelector">
<ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
</Style>
还需要在ItemContainerStyle
控件
ListBox
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListBox.ItemContainerStyle>