谁能解释如下的代码啊

gistop 2010-08-19 11:28:05
terrylee中,ListBox项水平放置代码如下,代码是对的,效果也是对的.
<ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal">
</StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBoxItem Content="1" Width="40"/>
<ListBoxItem Content="2" Width="40"/>
<ListBoxItem Content="3" Width="40"/>
<ListBoxItem Content="4" Width="40"/>
</ListBox>

但我不清楚为什么不是这样的形式:
<ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal">
<ListBoxItem Content="1" Width="40"/>
<ListBoxItem Content="2" Width="40"/>
<ListBoxItem Content="3" Width="40"/>
<ListBoxItem Content="4" Width="40"/>
</StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>

...全文
45 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
gistop 2010-08-22
  • 打赏
  • 举报
回复
ls的一语中的
jv9 2010-08-22
  • 打赏
  • 举报
回复
两段代码表示的完全不同,第一段代码定义了ItemsPanelTemplate的模板,其ListBoxItem的选项要根据该模板的定义来决定。

而第二段是只有模板显示ListBoxItem。

8,735

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧