ここに私がやろうとしていることの説明があります: ユーザーが肉のボタンを押したときにカタログ (ListView) が肉の写真でいっぱいになる製品のカタログを作成する必要があります。各行に 3 つの製品を含めたい.. .私がこれまでに持っているものは次のとおりです。
XAML:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:ImageConverter x:Key="ImageConverter"/>
<DataTemplate x:Key="imageListView">
<StackPanel>
<Image Source="{Binding .,Converter={StaticResource ImageConverter}}" Height="50" Width="100" />
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<ListView ItemsSource="{Binding ImageCollection}" ItemTemplate="{StaticResource imageListView}"/>
</Grid>
</Window>
XAML のバック コード:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
MyViewModel VM = new MyViewModel();
DataContext = VM;
}
}
class ImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is Bitmap)
return ConvertBitmapToBitmapImage((Bitmap)value);
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
private BitmapImage ConvertBitmapToBitmapImage(Bitmap bitmap)
{
MemoryStream memoryStream = new MemoryStream();
bitmap.Save(memoryStream, ImageFormat.Png);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = new MemoryStream(memoryStream.ToArray());
bitmapImage.EndInit();
return bitmapImage;
}
}
そして MyViewModel コード:
private List<Bitmap> m_ImageCollection;
public MyViewModel()
{
LoadImages();
}
void LoadImages()
{
m_ImageCollection = new List<Bitmap>();
ResourceManager rm = Properties.Resources.ResourceManager;
ResourceSet rs = rm.GetResourceSet(new CultureInfo("en-US"), true, true);
if (rs != null)
{
var images =
from entry in rs.Cast<DictionaryEntry>()
where entry.Value is Bitmap
select entry;
foreach (DictionaryEntry img in images)
{
if (img.Value is Bitmap)
m_ImageCollection.Add((Bitmap)img.Value);
}
}
}
public List<Bitmap> ImageCollection
{
get { return m_ImageCollection; }
set { m_ImageCollection = value; }
}
画像を読み込んでいますが、各画像を連続して 3 つの画像を連続して表示したいのですが...
ヘルプはありますか?