I'd like to move a project to WPF and in it I have an ImageList
(loaded by selecting 25 images in design view) that I use to create buttons with as follows:
I've simplified the project down to the following code. This is my whole project (aside from autogenerated code in .Designer.cs):
public partial class Form1 : Form
{
Button[] buttonList = new Button[25];
Size buttonSize = new Size(140, 140);
public Form1()
{
InitializeComponent();
this.ClientSize = new Size(142 * 5, 142 * 5);
for (int i = 0; i < buttonImages.Images.Count; i++)
{
buttonList[i] = new Button();
buttonList[i].Size = buttonSize;
buttonList[i].Location = new Point(
(i % 5) * (buttonSize.Width + 2) + 1,
(i / 5) * (buttonSize.Height + 2) + 1);
buttonList[i].Image = buttonImages.Images[i];
}
SuspendLayout();
Controls.AddRange(buttonList);
ResumeLayout(false);
}
}
I can't seem to wrap my head around how to do this trivial task in WPF. As best as I can tell from answers on here (like this) I should be
- Filling a folder with images
- Creating a ResourceDictionary referencing them
- Creating another file that references the ResourceDictionary reference
- Create a something else (I can't figure out what) that accesses the images through the ResourceDictionary to load them to buttons (but the button class doesn't even have a constructor...???!!!)
Can someone help translate this to WPF? Honestly, I just can't figure out where to start.
If it matters, here's what this looks like when it runs: