我正在开发一个Windows Phone 7应用程序。 我需要垂直显示频道列表。在每个频道旁边,我需要显示应该可以水平滚动的特定频道的节目。任何人都可以建议如何做到这一点吗?
答案 0 :(得分:0)
您可以使用嵌套列表框,在子列表中设置滚动查看器,沿着这一行开始的事情可以帮助您入门
public class Channel
{
public string Name { get; set; }
public IEnumerable<Program> Programs { get; set; }
}
public class Program
{
public string Name { get; set; }
}
在您的代码中
public MainPage()
{
InitializeComponent();
BindChannels();
}
private void BindChannels()
{
lstChannels.ItemsSource = new[]
{
new Channel { Name = "BBC 1", Programs = new[] { new Program { Name = "Abbey Town" }, new Program { Name = "Early Bird" }, new Program { Name = "East enders" } } },
new Channel { Name = "BBC 2", Programs = new[] { new Program { Name = "Dancing stars" }, new Program { Name = "David and G" }, new Program { Name = "The Eastern blocks" } } },
new Channel { Name = "ITV", Programs = new[] { new Program { Name = "X Factor" }, new Program { Name = "X Factor reloaded" }, new Program { Name = "The game" } } },
new Channel { Name = "Fox News", Programs = new[] { new Program { Name = "Early news" }, new Program { Name = "Talk C" }, new Program { Name = "Recap" } } }
};
}
Xaml
<ListBox x:Name="lstChannels">
<ListBox.ItemTemplate>
<DataTemplate>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled" Margin="0,6,0,0" Height="Auto">
<ListBox ItemsSource="{Binding Programs}" ScrollViewer.VerticalScrollBarVisibility="Disabled" Margin="12,0,0,0">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation ="Horizontal" >
<StackPanel.RenderTransform>
<TranslateTransform
X="0" />
</StackPanel.RenderTransform>
</StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Border Height="100" Width="200" BorderBrush="Bisque" BorderThickness="3">
<TextBlock Text="{Binding Name}"></TextBlock>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>