c# wpf 这段xaml代码怎么用c#表示

qq_34612730 2016-05-22 06:04:24
<ListViewItem Width="100" Margin="1">
<StackPanel>
<Image Source="地址"></Image>
<TextBlock>hehe</TextBlock>
</StackPanel>
</ListViewItem>

我会在后台动态创建listviewitem会,listviewitem的内容的添加怎么用c#表示
...全文
105 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
为轮子而生 2016-05-23
  • 打赏
  • 举报
回复
ListViewItem listViewItem = new ListViewItem{ Width = 100, Margin = new Thickness(1) }; StackPanel stackPanel = new StackPanel(); Image image = new Image{ Source = new BitmapImage(new Uri("1_guwei4037.jpg", UriKind.Relative)) }; TextBlock textBlock = new TextBlock { Text = "hehe" }; stackPanel.Children.Add(image); stackPanel.Children.Add(textBlock); listViewItem.Content = stackPanel;
全栈极简 2016-05-22
  • 打赏
  • 举报
回复
 ListViewItem listViewItem = new ListViewItem() { Width = 100, Margin = new Thickness(1) };

            StackPanel stackPanel = new StackPanel();
            Image image = new Image() { Source = new BitmapImage(new Uri("1_guwei4037.jpg", UriKind.Relative)) };
            TextBlock textBlock = new TextBlock() { Text = "hehe" };
            stackPanel.Children.Add(image);
            stackPanel.Children.Add(textBlock);

            listViewItem.Content = stackPanel;
            grid.Children.Add(listViewItem);

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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