【问题标题】:WPF/C#: How to add images from a horizontal listbox/listview by (file paths coming from a database table)WPF/C#:如何通过(来自数据库表的文件路径)从水平列表框/列表视图添加图像
【发布时间】:2010-05-06 05:19:34
【问题描述】:

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

【问题讨论】:

    标签: wpf filepath listboxitem horizontallist


    【解决方案1】:

    当然,只需为列表框定义一个自定义 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"};
    

    【讨论】:

    • 胖手指 + 冷 = 真正痛苦的数据绑定错误之一,直到运行时才明显。感谢您指出。
    猜你喜欢
    • 2010-11-25
    • 1970-01-01
    • 2013-01-15
    • 2014-05-12
    • 1970-01-01
    • 2011-09-18
    • 2023-03-26
    相关资源
    最近更新 更多