WPF/C#:如何通过(来自数据库表的文件路径)从水平列表框/列表视图添加图像

发布于 2024-08-31 07:50:07 字数 189 浏览 2 评论 0原文

有没有办法水平自定义列表框/列表视图并添加来自具有图像文件路径记录的数据库的项目(图像)?

替代文本

Is there are way to customize the listbox/listview horizontally and add items (images) coming from a database which has a record of image file paths?

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许你一世情深 2024-09-07 07:50:07

当然,只需为列表框定义一个自定义 ItemTemplate 即可显示图像。还要覆盖 ItemsPanel 以使其水平。

<ListBox ItemsSource={Binding CollectionOfFilePaths}>

<ListBox.ItemsPanel>
  <ItemsPanelTemplate>
    <StackPanel Orientation="Horizontal"/>
  </ItemsPanelTemplate>
</ListBox.ItemsPanel>

  <ListBox.ItemTemplate>
    <DataTemplate>
      <Image Source="{Binding}"/>
    </DataTemplate>
  </ListBox.ItemTemplate>
<ListBox>

然后在代码隐藏中:

ObservableCollection<string> CollectionOfFilePaths{get;set;}
//....
CollectionOfFilePaths= new ObservableCollection<string>{"c:\filepath1.jpg","c:\filepath1.jpg"};

Sure, just define a custom ItemTemplate for the listbox to show the image. Also override ItemsPanel to make it horizontal.

<ListBox ItemsSource={Binding CollectionOfFilePaths}>

<ListBox.ItemsPanel>
  <ItemsPanelTemplate>
    <StackPanel Orientation="Horizontal"/>
  </ItemsPanelTemplate>
</ListBox.ItemsPanel>

  <ListBox.ItemTemplate>
    <DataTemplate>
      <Image Source="{Binding}"/>
    </DataTemplate>
  </ListBox.ItemTemplate>
<ListBox>

Then in codebehind:

ObservableCollection<string> CollectionOfFilePaths{get;set;}
//....
CollectionOfFilePaths= new ObservableCollection<string>{"c:\filepath1.jpg","c:\filepath1.jpg"};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文