这是我的 XAML
<Window.Resources>
<DataTemplate x:Key="listBoxTemplate">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding thumb}" Height="100" Width="130" Margin="5"></Image>
<StackPanel Orientation="Vertical" Width="247">
<TextBlock Text="{Binding recipeName}" Height="60" Padding="15" FontSize="16" HorizontalAlignment="Stretch" VerticalAlignment="Center"></TextBlock>
<TextBlock Text="{Binding cuisine}" Height="60" Padding="15" FontSize="16" HorizontalAlignment="Stretch" VerticalAlignment="Center"></TextBlock>
</StackPanel>
</StackPanel>
</DataTemplate>
</Window.Resources>
和我的代码:
conn = new SQLiteConnection(connString);
cmd = new SQLiteCommand();
dtSet = new DataSet();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT id,recipeName,cuisine,thumb FROM RECIPES";
dataAdapter = new SQLiteDataAdapter();
dataAdapter.SelectCommand = cmd;
try{
dataAdapter.Fill(dtSet,"recipes");
listBox1.DataContext = dtSet;
}
问题是图像没有出现。假设从sqlite返回的拇指是图像文件名1.jpg,2.jpg等..那么我应该把图像放在哪里让它出现在程序中?在哪个文件夹?
我在使用 StringFormat和https://stackoverflow.com/questions/3717968/button-image-source-binding-using-string-format-in-wpf绑定 WPF 图像源时遇到了确切的问题,我需要答案制作某种将图像路径转换为位图源的转换器。但作为菜鸟,我真的不知道该怎么做。