<ListBox x:Name="lstbox" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Visible">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
我可以通过此设计时间代码创建水平滚动图像列表
现在我能够在运行时添加图像,
但我无法通过运行时的代码生成相同的效果....
答案 0 :(得分:3)
一种方法:
string xaml =
"<ListBox x:Name='lstbox' ScrollViewer.VerticalScrollBarVisibility='Disabled' ScrollViewer.HorizontalScrollBarVisibility='Visible'>"+
"<ListBox.ItemsPanel>"+
"<ItemsPanelTemplate>"+
"<StackPanel Orientation='Horizontal' />"+
"</ItemsPanelTemplate>"+
"</ListBox.ItemsPanel>";
UIElement tree = (UIElement)XamlReader.Load(xaml);
LayoutRoot.Children.Add(tree);