Creating a round border around user avatar in .NET MAUI - maui

In my .NET MAUI app, I'm using the AvatarView in.NET MAUI Community Toolkit to create a nicely round user avatar which is pretty easy to do.
I now want to put a nice border around the image but I'm not getting the desired effect because when I set the BorderWidth property of the AvatarView, it places the border "inside" the image which makes the visible area smaller. I actually want to put the border "outside" the image so that I don't lose anything from the visible area. Here's an image that demonstrates this:
BTW, I tried setting the HeightRequest and WidthRequst larger and then setting the BorderWidth but it still seems to make the visible area smaller because all that's doing is that it makes the main image larger and with the border set, the visible area still doesn't show the additional data/area.
Here's my current code which places the border within the image -- which I can safely assume is the standard behavior.
<mct:AvatarView
ImageSource="{Binding UserInfo.AvatarUrl}"
BorderColor="{StaticResource UILightGray}"
BorderWidth="10"
CornerRadius="70"
HeightRequest="140"
WidthRequest="140"/>
How do I achieve the effect that I want? Basically, I'd like the border to go outside of the image, effectively adding some 10 pixels to the size of the image.
Alternatively, I don't mind placing the border within the image but I need a way to make the actual image 10 pixel smaller so that the visible area stays the same.
How can I achieve this by using or not using .NET MAUI Community Toolkit?

If you don't want to use the community toolkit package, then wrap the image with a Frame would be a trade-off for this scenario. And also you need to set the Aspect of the image to AspectFit.
<Frame HeightRequest="140"
WidthRequest="140"
CornerRadius="70"
HorizontalOptions="Center"
IsClippedToBounds="True"
Padding="0"
BorderColor="Gray"
Margin="0,0,0,0">
<Image
Aspect="AspectFit"
Source="dotnet_bot.png"
SemanticProperties.Description="Cute dot net bot waving hi to you!"
HeightRequest="140"
WidthRequest="140"
VerticalOptions="Center"
HorizontalOptions="Center" />
</Frame>
Update:
You can also wrap a Border as Steve suggested.
<Border HeightRequest="160"
WidthRequest="160"
StrokeShape="RoundRectangle 80,80,80,80"
HorizontalOptions="Center"
StrokeThickness="8"
Margin="0,0,0,0">
<Image
Aspect="AspectFit"
Source="dotnet_bot.png"
SemanticProperties.Description="Cute dot net bot waving hi to you!"
HeightRequest="160"
WidthRequest="160"
VerticalOptions="Center"
HorizontalOptions="Center" />
</Border>

Related

Transparent png image not showing as transparent in Xamarin Absolute Layout

Transparent png image not showing as transparent in Xamarin Absolute Layout
<AbsoluteLayout BackgroundColor="Aqua">
<Image Source="#drawable/icon.png" AbsoluteLayout.LayoutBounds="0.5,0.5,30,30"
AbsoluteLayout.LayoutFlags="PositionProportional" />
</AbsoluteLayout>
Just change your background color to transparent in your <Image>.
Something like that.
<Image Source="#drawable/icon.png" BackgroundColor="Transparent" AbsoluteLayout.LayoutBounds="0.5,0.5,30,30"
AbsoluteLayout.LayoutFlags="PositionProportional" />

Xaml Xamarin Forms Absolute Layout Overlap

Given the above image, how would I go about to setup my Absolute Layouts?
I would like to have my blue absolute layout overlap the red border absolute layout. I understand there's a doc explaining how AbsoluteLayouts work however I still don't completely understand it 100%.
I have tried setting up the layouts the following way but the blue square is always hidden.
With the below code I don't end up seeing the blue layout at all.
<AbsoluteLayout>
<AbsoluteLayout x:Name="BlueSquare">
<StackLayout> (Asumme there is a list of things in here) </StackLayout>
</AbsoluteLayout>
<AbsoluteLayout x:Name="RedBorderArea">
<StackLayout> (Asumme there is another list of stuff in here) </StackLayout>
</AbsoluteLayout>
</AbsoluteLayout>
After tinkering around I needed to add the Blue square layout last and i removed the RedSquares parent layout.
<AbsoluteLayout>
<StackLayout x:Name="RedBorderArea" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0.5,0.5,1,1"> (Asumme there is another list of stuff in here) </StackLayout>
<AbsoluteLayout x:Name="BlueSquare" LayoutFlags="PositionProportional, WidthProportional" LayoutBounds="1,0,1,1">
<StackLayout> (Asumme there is a list of things in here) </StackLayout>
</AbsoluteLayout>
</AbsoluteLayout>

How to make zk boderlayout to fit any resolution screen

<window height="300px">
<borderlayout >
<north height="60px" ></north>
<west width="200px" ></west>
<center></center>
<east width="200px" ></east>
<south height="40px"></south>
</borderlayout>
</window>
Currently i have to set the window height to a pixel value for this to work properly..
So if my screen resolution height is 300px then it will cover the complete screen.
But will not fill up the complete screen for different resolutions...
How to make this hardcoded value to be dynamic based to user screen resolution ?
I cannot remove window tag.
zkfiddle example
<window height="100%">
should do the trick.
Maybe Media Queries could be interesting for you too.

Tumblr Photoset not working

The theme I've chosen has decided to reduce photosets to the first frame, instead of giving the full photoset. I want a consolidated photoset shown on my page, instead of the first, single. I have no idea how to do this. I've tried looking on here, using this:
{block:Photoset}
{block:Photos}
<img src="{PhotoURL-500}" class="photoset-img" />
{/block:Photos}
{/block:Photoset}
It worked, sort of. All the photos of the set were there, but they were large and connected together. The images in the photoset are now stacked vertically atop one another instead of side by side and are taking up a lot of space.
The theme block / variable below will generate an iframe containing the images, laid out, as they were set on the dashboard.
{block:Photoset}
{Photoset-500}
{/block:Photoset}

GWT Layout: "take up the rest of the space."

My existing layout is a stack of two divs - g:layers in a LayoutPanel. The top div should be as big as it needs to be to contain its contents. The bottom div should take up the rest of the space on the screen, without causing scrollbars to appear.
The contents of the top div can change, so the size of the top div can change.
My current solution is a callback that's triggered whenever the contents of the top div change. The containing LayoutPanel can then recalculate the size of the top div and explicitly set the top and bottom attributes of the second layer to take up the rest of the space. Is there a better way? Something like,
<g:LayoutPanel>
<g:layer top="0px" height="whatever you need, baby">
<c:SomeWidget/>
</g:layer>
<g:layer top="the bottom of the first layer" bottom="0px">
<c:Anotherwidget/>
</g:layer>
</g:LayoutPanel>
What about using DockLayoutPanel?
<g:DockLayoutPanel unit='PX'>
<north size="10" ui:field='northWidget'>
<c:SomeWidget/>
</north>
<center>
<c:Anotherwidget/>
</center>
</g:DockLayoutPanel>
Then the center will take up the rest of the space. If you want to resize the top, call
setWidgetSize(northWidget, newSize); and the center widget will be recalculated.
The answer seems to be that there is not a better way. Manual recalculation isn't so bad when you get used to it!
I think HeaderPanel is the standard Widget to do this. Maybe it was added after the question was asked. We missed it too and had our own version for a while.