Ripple Effect in .NET MAUI Effects View (SfEffectsView)
28 Jul 202613 minutes to read
The SfEffects.Ripple is an expandable circle that originates at the touch point and grows until the entire Effects View is filled. Use it to provide Material-style touch feedback on any view.
The size of the ripple at the start of the animation is controlled by the InitialRippleFactor property. The ripple is drawn inside the bounds of the Effects View, not the parent layout.
Adding a Basic Ripple
The example below applies a ripple to the Effects View while the user is touching it.
<Border HorizontalOptions="Center"
VerticalOptions="Center">
<Border.StrokeShape>
<RoundRectangle CornerRadius="18" />
</Border.StrokeShape>
<Border.Background>
<LinearGradientBrush EndPoint="1,0">
<GradientStop Color="#FFCDCDD2"
Offset="0.0" />
<GradientStop Color="#FFCDCDD2"
Offset="1.0" />
</LinearGradientBrush>
</Border.Background>
<syncEffectsView:SfEffectsView TouchDownEffects="Ripple">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="90" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Source="laura.png"
Margin="7"
VerticalOptions="Center"
WidthRequest="72"
HeightRequest="72" />
<StackLayout Grid.Column="1"
VerticalOptions="Center">
<Label Text="Laura Steffi"
Margin="10,0,10,0"
FontSize="18" />
<Label Text="Data Science Analyst"
Margin="10,0,10,0"
FontSize="12"/>
</StackLayout>
</Grid>
</syncEffectsView:SfEffectsView>
</Border>var grid = new Grid
{
ColumnDefinitions =
{
new ColumnDefinition { Width = 90 },
new ColumnDefinition { Width = GridLength.Star }
}
};
var image = new Image
{
Source = "laura.png",
Margin = new Thickness(7),
VerticalOptions = LayoutOptions.Center,
WidthRequest = 72,
HeightRequest = 72
};
var nameLabel = new Label
{
Text = "Laura Steffi",
Margin = new Thickness(10, 0),
FontSize = 18
};
var roleLabel = new Label
{
Text = "Data Science Analyst",
Margin = new Thickness(10, 0),
FontSize = 12
};
var stackLayout = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Children = { nameLabel, roleLabel }
};
grid.Add(image);
grid.Add(stackLayout, 1, 0);
var effectsView = new SfEffectsView
{
TouchDownEffects = SfEffects.Ripple,
Content = grid
};
var border = new Border
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
StrokeShape = new RoundRectangle
{
CornerRadius = 18
},
Background = new LinearGradientBrush
{
EndPoint = new Point(1, 0),
GradientStops = new GradientStopCollection
{
new GradientStop(Color.FromArgb("#FFCDCDD2"), 0.0f),
new GradientStop(Color.FromArgb("#FFCDCDD2"), 1.0f)
}
},
Content = effectsView
};
this.Content = border;
Customizing the Ripple
The example below sets a custom ripple color and an initial factor of 0.25 (one quarter of the view’s smaller dimension).
<Border HorizontalOptions="Center"
VerticalOptions="Center">
<Border.StrokeShape>
<RoundRectangle CornerRadius="18" />
</Border.StrokeShape>
<Border.Background>
<LinearGradientBrush EndPoint="1,0">
<GradientStop Color="#FFCDCDD2"
Offset="0.0" />
<GradientStop Color="#FFCDCDD2"
Offset="1.0" />
</LinearGradientBrush>
</Border.Background>
<syncEffectsView:SfEffectsView TouchDownEffects="Ripple"
RippleBackground="Red"
InitialRippleFactor="0.25">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="90" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Source="laura.png"
Margin="7"
VerticalOptions="Center"
WidthRequest="72"
HeightRequest="72" />
<StackLayout Grid.Column="1"
VerticalOptions="Center">
<Label Text="Laura Steffi"
Margin="10,0,10,0"
FontSize="18" />
<Label Text="Data Science Analyst"
Margin="10,0,10,0"
FontSize="12"/>
</StackLayout>
</Grid>
</syncEffectsView:SfEffectsView>
</Border>var grid = new Grid
{
ColumnDefinitions =
{
new ColumnDefinition { Width = 90 },
new ColumnDefinition { Width = GridLength.Star }
}
};
var image = new Image
{
Source = "laura.png",
Margin = new Thickness(7),
VerticalOptions = LayoutOptions.Center,
WidthRequest = 72,
HeightRequest = 72
};
var nameLabel = new Label
{
Text = "Laura Steffi",
Margin = new Thickness(10, 0),
FontSize = 18
};
var roleLabel = new Label
{
Text = "Data Science Analyst",
Margin = new Thickness(10, 0),
FontSize = 12
};
var stackLayout = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Children = { nameLabel, roleLabel }
};
grid.Add(image);
grid.Add(stackLayout, 1, 0);
var effectsView = new SfEffectsView
{
TouchDownEffects = SfEffects.Ripple,
RippleBackground = new SolidColorBrush(Colors.Red),
InitialRippleFactor = 0.25,
Content = grid
};
var border = new Border
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
StrokeShape = new RoundRectangle
{
CornerRadius = 18
},
Background = new LinearGradientBrush
{
EndPoint = new Point(1, 0),
GradientStops = new GradientStopCollection
{
new GradientStop(Color.FromArgb("#FFCDCDD2"), 0.0f),
new GradientStop(Color.FromArgb("#FFCDCDD2"), 1.0f)
}
},
Content = effectsView
};
this.Content = border;