怎样在cs代码中设置listbox的itemsPanelTemplate?

kenei 2014-10-13 05:46:11

<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>


如上这种xaml代码如何在cs代码中编写?
因为要根据代码动态设置itemsPanel,而看到的资料都是在xaml中设置,不知道怎么在cs代码中设置.
请教各位达人,谢谢.
...全文
236 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kenei 2014-10-14
  • 打赏
  • 举报
回复
引用 4 楼 u011785544 的回复:
[quote=引用 2 楼 kenei 的回复:] [quote=引用 1 楼 u011785544 的回复:] [quote=引用 楼主 kenei 的回复:]

<ListBox.ItemsPanel>
   <ItemsPanelTemplate>
      <WrapPanel Orientation="Vertical />
   </ItemsPanelTemplate>
</ListBox.ItemsPanel>
如上这种xaml代码如何在cs代码中编写? 因为要根据代码动态设置itemsPanel,而看到的资料都是在xaml中设置,不知道怎么在cs代码中设置. 请教各位达人,谢谢.
itemsPanelTemplate中的控件也需要CS加入么?还是想去控制页面上itemsPanelTemplate中已经有的控件?[/quote]\ 也在CS里加入,就是new 一个 wrapPanel.[/quote] 希望对你有帮助 http://stackoverflow.com/questions/18736677/how-to-code-orientation-of-listbox-wpf-c-sharp[/quote] 谢谢,要的就是这个.
Veary 2014-10-14
  • 打赏
  • 举报
回复
引用 2 楼 kenei 的回复:
[quote=引用 1 楼 u011785544 的回复:] [quote=引用 楼主 kenei 的回复:]

<ListBox.ItemsPanel>
   <ItemsPanelTemplate>
      <WrapPanel Orientation="Vertical />
   </ItemsPanelTemplate>
</ListBox.ItemsPanel>
如上这种xaml代码如何在cs代码中编写? 因为要根据代码动态设置itemsPanel,而看到的资料都是在xaml中设置,不知道怎么在cs代码中设置. 请教各位达人,谢谢.
itemsPanelTemplate中的控件也需要CS加入么?还是想去控制页面上itemsPanelTemplate中已经有的控件?[/quote]\ 也在CS里加入,就是new 一个 wrapPanel.[/quote] 希望对你有帮助 http://stackoverflow.com/questions/18736677/how-to-code-orientation-of-listbox-wpf-c-sharp
exception92 2014-10-14
  • 打赏
  • 举报
回复
代码设置太麻烦,在xaml中也可以动态设置模板。 https://social.msdn.microsoft.com/forums/azure/pt-br/ac948850-651e-4615-8d14-f8453160a6ec/-wpf-c
kenei 2014-10-14
  • 打赏
  • 举报
回复
引用 1 楼 u011785544 的回复:
[quote=引用 楼主 kenei 的回复:]

<ListBox.ItemsPanel>
   <ItemsPanelTemplate>
      <WrapPanel Orientation="Vertical />
   </ItemsPanelTemplate>
</ListBox.ItemsPanel>
如上这种xaml代码如何在cs代码中编写? 因为要根据代码动态设置itemsPanel,而看到的资料都是在xaml中设置,不知道怎么在cs代码中设置. 请教各位达人,谢谢.
itemsPanelTemplate中的控件也需要CS加入么?还是想去控制页面上itemsPanelTemplate中已经有的控件?[/quote]\ 也在CS里加入,就是new 一个 wrapPanel.
Veary 2014-10-14
  • 打赏
  • 举报
回复
引用 楼主 kenei 的回复:

<ListBox.ItemsPanel>
   <ItemsPanelTemplate>
      <WrapPanel Orientation="Vertical />
   </ItemsPanelTemplate>
</ListBox.ItemsPanel>
如上这种xaml代码如何在cs代码中编写? 因为要根据代码动态设置itemsPanel,而看到的资料都是在xaml中设置,不知道怎么在cs代码中设置. 请教各位达人,谢谢.
itemsPanelTemplate中的控件也需要CS加入么?还是想去控制页面上itemsPanelTemplate中已经有的控件?

8,735

社区成员

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

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