Hi MIPAKTEH_1,
Thank you for reaching out to Microsoft Q & A forum.
To achieve this functionality, you need to track the selected item and update it when a menu item is clicked.
Modify the TShirtItem.razor file to store the selected item.
@page "/tshirt-items"
@using TestBlazorApp.Models
<h3>Item</h3>
<div class="container">
<div class="preview">
@if (selectedItem != null)
{
<img src="@selectedItem.ImagePath" alt="Selected T-Shirt" />
}
</div>
<div class="menu">
@foreach (var item in tshirtItems)
{
<button @onclick="() => SelectItem(item)">@item.Name</button>
}
</div>
</div>
@code {
private List<TShirtItem> tshirtItems = new()
{
new() { ImagePath = "images/Pakaian_1.jfif", Name = "Shirt 1" },
new() { ImagePath = "images/Pakaian_5.jfif", Name = "Shirt 2" }
};
private TShirtItem? selectedItem;
private void SelectItem(TShirtItem item) => selectedItem = item;
}
Ensure that clicking a button updates the displayed image accordingly.
The menu buttons should appear on the right, while the corresponding image updates on the left when a button is clicked.
Please feel free to contact us if you have any additional questions.
If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community.