XAML Ellipse not working - xaml

I can't seem to get Ellipse to work at all in my Xamarin project.
It just says "The type or namespace name 'ImageBrush' does not exist in the namespace 'Xamarin.Forms' (are you missing an assembly reference?)" and I have no clue what's up. I've checked video's but there everything seems to work fine...
Anyone know what I'm doing wrong?
EDIT:
I forgot to post the code along with the question. Thanks for the reminder!
I'm trying to get the Logo.png to display as a circle. I
I can't seem to get Ellipse to work at all in my Xamarin project.
It just says "The type or namespace name 'ImageBrush' does not exist in the namespace 'Xamarin.Forms' (are you missing an assembly reference?)" and I have no clue what's up. I've checked video's but there everything seems to work fine...
Anyone know what I'm doing wrong?
EDIT:
I forgot to post the code along with the question. Thanks for the reminder!
I'm trying to get the Logo.png to display as a circle. I
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="GrowersClassified.Views.LoginPage">
<StackLayout x:Name="MasterLayout">
<StackLayout x:Name="LogoStack" Padding="40, 80, 40 , 0">
<Ellipse Height="100" Width="100">
<Ellipse.Fill>
<ImageBrush ImageSource="Logo.png"/>
</Ellipse.Fill>
</Ellipse>
</StackLayout>
<StackLayout Padding="40, 20, 40, 0">
<StackLayout x:Name="LoginEntries" VerticalOptions="StartAndExpand">
<ActivityIndicator x:Name="ActivitySpinner" Color="Red" IsRunning="True"></ActivityIndicator>
<Label x:Name="Lbl_Username" Text="Username"/>
<Entry x:Name="Entry_Username" Placeholder="Username"/>
<Label x:Name="Lbl_Password" Text="Password"/>
<Entry x:Name="Entry_Password" Placeholder="Password"/>
<Button x:Name="Btn_Signin" Text="Log in" Clicked="SigninProcedure"/>
</StackLayout>
</StackLayout>
</StackLayout>
</ContentPage>

Related

Maui framework doesn't display sliders correctly

I have been dipping my toes in the .NET Maui framework, but unfortunately so far it has been quite disappointing. There seem to be multiple errors related to Shell (title view not working properly) and controls themselves. I have the following main page xaml file:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiApp1.MainPage">
<StackLayout Background="#111111" >
<Frame HasShadow="True" Margin="10" CornerRadius="10" BackgroundColor="#222222">
<StackLayout Spacing="30">
<Grid ColumnDefinitions="30,*">
<Label Text="R" FontSize="Medium" TextColor="White" />
<Slider GridLayout.Column="1" MinimumTrackColor="Red" ThumbColor="Red" MaximumTrackColor="#AAAAAA" />
</Grid>
<Grid ColumnDefinitions="30,*">
<Label Text="G" FontSize="Medium" TextColor="White" />
<Slider GridLayout.Column="1" MinimumTrackColor="#7FFF00" ThumbColor="#7FFF00" MaximumTrackColor="#AAAAAA" />
</Grid>
</StackLayout>
</Frame>
</StackLayout>
</ContentPage>
which is just a stack layout with a single frame that houses two sliders with labels. However, the two sliders seem to have a predefined width, as they are not filling the remaining space:
As soon as I add anything to any of the controls in the xaml while the app is running, for example a green background to the first grid, both sliders resize to the correct size:
However, when I reload the application with this change, the sliders go back to the wrong size:
There are additional issues that I encountered as well, when placing this content page as a flyout item in the shell where android behaviour was as described here, but additionally the Sliders are not interactable in Windows version. In this example with a clean project they do work in Windows version.
Try with any third-party packages like syncfusion, etc. to meet your requirements.

Xamarin.Forms DynamicResource doesn't seem to be working

I can't seem to get a DynamicResource working correctly.
Here's the XAML in App.xml:
<Application.Resources>
<ResourceDictionary>
<Thickness x:Key ="DefaultInsets"
Bottom="4"
Top ="4"
Left ="8"
Right ="8" />
</ResourceDictionary>
</Application.Resources>
And here's what I'm trying to do inside another file's ContentView:
<StackLayout
VerticalOptions="Center"
HeightRequest="225"
Margin="{DynamicResource DefaultInsets}" >
<Entry
x:Name="nameControl"
Placeholder="Full Name"
Margin="{DynamicResource DefaultInsets}"
/>
<Entry
x:Name="passwordControl"
IsPassword="True"
Placeholder="Password"
Margin="{DynamicResource DefaultInsets}" />
</StackLayout>
It seems like this should make consistent insets for the StackLayout from the ContentView, and for the Entry fields from the StackLayout. But I don't see any of that.
What have I done wrong?
Update : I have also tried this with StaticResource, and still no luck.
I use following type with ResourceDictionary. For distinguish, I set the top_margin to 40, here is my screenshot.
Here is my ResourceDictionary.
<Application.Resources>
<ResourceDictionary>
<OnPlatform x:Key="OuterPadding" x:TypeArguments="Thickness">
<On Platform="Android">8 ,40,8,4</On>
<On Platform="iOS">20</On>
<On Platform="WinPhone">24</On>
</OnPlatform>
<!-- left, top, right, and bottom-->
</ResourceDictionary>
</Application.Resources>
Here is my layout.
<StackLayout
VerticalOptions="Center"
HeightRequest="225"
Margin="{DynamicResource OuterMargin}" >
<Entry
x:Name="nameControl"
Placeholder="Full Name"
Margin="{DynamicResource OuterMargin}"
/>
<Entry
x:Name="passwordControl"
IsPassword="True"
Placeholder="Password"
Margin="{DynamicResource OuterMargin}" />
</StackLayout>
Update
I found you layout issue is related to the VerticalOptions="Center" in the StackLayout(If you set the VerticalOptions="Center", then set the margin value is not work).
If I delete it and use StaticResource.
Here is running screenshot(For testing, I change the value of margin top to 20)
Other answers may be valid for some people, but in the end here's what I was doing wrong:
InitializeComponent() was never getting called inside App.xaml.cs.
I had an if-then statement that was always hitting a return before ever getting to InitializeComponent().
When that doesn't get called, App.xaml is inaccessible to the rest of the app, and nothing defined there is available as a DynamicResource.
So I moved InitializeComponent() to happen before the if-then statement, and now it all works like gangbusters.
I hope this helps someone!

Buttons in an AbsoluteLayout overlap other objects on Android

So I have an odd thing happening with last Xamarin update and I am not sure what to do about it.
I have a view
<ContentView.Content>
<AbsoluteLayout WidthRequest="100" HeightRequest="100">
<Button x:Name="BackgroundButton" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1" />
<Image x:Name="Icon" InputTransparent="True" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1" Margin="20,15,20,25"/>
<Label x:Name="CountLabel" Style="{StaticResource HubButtonLabel}" HorizontalTextAlignment="End" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1" />
<Label x:Name="ButtonLabel" Style="{StaticResource HubButtonLabel}" HorizontalTextAlignment="Center" VerticalTextAlignment="End" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1" />
</AbsoluteLayout>
</ContentView.Content>
</ContentView>
Is basically just a button wrapper, with some extra icons, and text. I have a few of these in the project of different layouts and styles. Until the last update they worked fine. Now the button renders overtop of everything else. I can confirm that by setting the button color to something semi transparent.
This only happens on Android, it still works as expected on ios
Anyone have a fix for that? or do I need to rework all these views?
Update - So while this isn't really a fix, but also kind of is. If I swap out the Button for an ImageButton - they work again as expected on both platforms.
Bug perhaps with button on Android?
Got an answer on another forum. - Apparently it is a known bug with an easy fix, https://forums.xamarin.com/discussion/comment/394729
Put
global::Xamarin.Forms.Forms.SetFlags("UseLegacyRenderers");
Before the xamarin init in Main Activity Oncreate.

Image not displaying XAML android

I am trying xamarin forms for the first time so that I can build my app fro android and Iphone
I need to add an image to my layout MainPage.xaml and have this layout.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ReassuredMobileApp"
x:Class="ReassuredMobileApp.MainPage">
<StackLayout
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand">
<StackLayout
VerticalOptions="Start"
HorizontalOptions="FillAndExpand"
AutomationId="TitleBar">
<Label
Text="Hello, world!"></Label>
<Image
WidthRequest="200"
HeightRequest="50"
VerticalOptions="Start"
HorizontalOptions="Start"
Source="reassured_text.png" />
</StackLayout>
</StackLayout>
But the image "reassured_text.png" is not being displayed when I run the app in the emulator. I can see the Hello, World! text just fine (still cant see the image when I remove this)
My image is under my project as "reassured_text.png"
I've tried to follow tutorials online, but don't understand what is being said, and the ones I could understand didn't work. I've also tried to format the tag like
<Image
####Stuff here>
</Image>
but that didn't have an effect.
Directory tree:
Solution 'MyApp'
c# - MyApp
Dependencies
App.xaml
App.xaml.cs
MainPage.xaml
MainPage.xaml.cs
reassured_text.png
MyApp.Android
drawable
reassured_text.png
drawable-hdpi
drawable-xhdpi
drawable-xxhdpi
layout
values
MyApp.Ios
//I haven't touched anything here
1.Put the image reassured_text.png in Android project i.e in Resource/Drawable folder.
or
2.Put the image reassured_text.png in portable project & set build action to "Embedded Resource" & in .cs file do like this:
imagecontrol.FromResource="reassured_text.png";

Property Content is null or is not IEnumerable

I have a test page in Xamarin.Forms and it gets me this error, how can I fix this ?
Property Content is null or is not IEnumerable
Xaml :
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Project1.Page1">
<ContentPage.Content>
<Label Text="Page"></Label>
<Editor Text="I am an Editor" />
</ContentPage.Content>
</ContentPage>
The Content property is of type View. You cannot have two views into it. Replace it with
<StackLayout >
<Label Text="Page"></Label>
<Editor Text="I am an Editor" />
<StackLayout>
If anyone else lands here from google and the above wasn't the fix. For me it was because I had a view with a Grid.Row="0" property set even though I accidentally placed it outside the bounds of the actual grid.