A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
Use a control that supports click/tap and navigation, or attach a behavior to the Image.
Two common approaches in .NET MAUI:
- Replace
ImagewithImageButtonand handleClicked:
<ImageButton x:Name="ImageIcon"
Grid.Row="1"
Grid.RowSpan="4"
Grid.Column="0"
Source="{Binding ImageSource}"
HeightRequest="50"
Clicked="OnImageIconClicked" />
Code-behind of the page that hosts this ContentView:
void OnImageIconClicked(object sender, EventArgs e)
{
// Navigate to a page that shows the larger image
// assuming NavigationPage is used and ImageSource is bound
var vm = BindingContext; // or ((ImageButton)sender).BindingContext
Navigation.PushAsync(new LargeImagePage(vm));
}
LargeImagePage would contain an Image with a larger HeightRequest/Aspect and its Source bound to the same image property.
ImageButton is designed exactly for “image that behaves like a button” and exposes Clicked and Command for navigation.
- Keep
Imageand use a behavior that reacts to touch
If using .NET MAUI Community Toolkit, attach ImageTouchBehavior to change the image on press/hover and handle navigation via command:
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
<Image x:Name="ImageIcon"
Grid.Row="1"
Grid.RowSpan="4"
Grid.Column="0"
Source="{Binding ImageSource}"
HeightRequest="50">
<Image.Behaviors>
<toolkit:ImageTouchBehavior
Command="{Binding ShowLargeImageCommand}" />
</Image.Behaviors>
</Image>
In the viewmodel:
public ICommand ShowLargeImageCommand => new Command(async () =>
{
await Shell.Current.GoToAsync("largeimagepage");
});
Then define a Shell route for the large-image page and bind its Image.Source to the appropriate property.
Both approaches give a tappable image that navigates to a new view with a larger image; ImageButton is the simplest when only a click is needed.
References: