Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@
</VerticalStackLayout.Resources>
<Label Style="{StaticResource Description}" Text="AvatarView can use local or URL image sources." />
<Line Style="{StaticResource HR}" />
<HorizontalStackLayout HorizontalOptions="Center" Spacing="12">
<Button
Margin="10"
Clicked="Button_OnClicked"
Text="Press me" />

<mct:AvatarView
BorderColor="Red"
HeightRequest="32"
Text="AV"
WidthRequest="32"
x:Name="buggyImage" />
</HorizontalStackLayout>

<Grid
ColumnDefinitions="Auto"
HorizontalOptions="Center"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ namespace CommunityToolkit.Maui.Sample.Pages.Views;
public partial class AvatarViewImagesPage : BasePage<AvatarViewImagesViewModel>
{
public AvatarViewImagesPage(AvatarViewImagesViewModel avatarViewImagesViewModel) : base(avatarViewImagesViewModel) => InitializeComponent();

void Button_OnClicked(object? sender, EventArgs e)
{
buggyImage.ImageSource = ImageSource.FromFile("avatar_icon.png");
}
}
27 changes: 17 additions & 10 deletions src/CommunityToolkit.Maui/Views/AvatarView.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ void HandleImageChanged(ImageSource? newValue)
avatarImage.Source = newValue;
if (newValue is not null)
{
RefreshAvatarImage();
Content = avatarImage;
}
Comment thread
Pastajello marked this conversation as resolved.
else
Expand All @@ -328,17 +329,23 @@ void HandleImageChanged(ImageSource? newValue)
void HandlePropertyChanged(object? sender, PropertyChangedEventArgs e)
{
// Ensure avatarImage is clipped to the bounds of the AvatarView whenever its Height, Width, CornerRadius and Padding properties change
if ((e.PropertyName == HeightProperty.PropertyName
|| e.PropertyName == WidthProperty.PropertyName
|| e.PropertyName == PaddingProperty.PropertyName
|| e.PropertyName == ImageSourceProperty.PropertyName
|| e.PropertyName == BorderWidthProperty.PropertyName
|| e.PropertyName == CornerRadiusProperty.PropertyName
|| e.PropertyName == StrokeThicknessProperty.PropertyName)
&& Height >= 0 // The default value of Height (before the view is drawn onto the page) is -1
&& Width >= 0 // The default value of Y (before the view is drawn onto the page) is -1
&& avatarImage.Source is not null)
if (e.PropertyName == HeightProperty.PropertyName
|| e.PropertyName == WidthProperty.PropertyName
|| e.PropertyName == PaddingProperty.PropertyName
|| e.PropertyName == BorderWidthProperty.PropertyName
|| e.PropertyName == CornerRadiusProperty.PropertyName
|| e.PropertyName == StrokeThicknessProperty.PropertyName
Comment thread
TheCodeTraveler marked this conversation as resolved.
Outdated
)
{
RefreshAvatarImage();
}
Comment thread
Pastajello marked this conversation as resolved.
}

void RefreshAvatarImage()
{
if (Height >= 0 // The default value of Height (before the view is drawn onto the page) is -1
&& Width >= 0 // The default value of Width (before the view is drawn onto the page) is -1
&& avatarImage.Source is not null)
{
Geometry? avatarImageClipGeometry = null;
#if WINDOWS
Expand Down
Loading