Image not displaying XAML android - xaml

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";

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.

Button icon doesn't show xamarins forms xaml

I'm new in xaml, and I have an issue. I'm trying to create a button with an icon next to my text in xamarin.forms. But when I'm trying to display it, I have nothing on my app. To add the png icon. The image is located in the Ressources->drawable folder. Here's the xaml code.
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="epicture.MainPage">
<StackLayout>
<Button Text="Log in" ImageSource="login.png" Clicked="Button_Clicked" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" BackgroundColor="#00c851" TextColor="White"></Button>
<WebView Navigating="WebView_Navigating"></WebView>
</StackLayout>
</ContentPage>
I also face same issue ImageButton not have text property.
Because of that I created Custom ImageButton Control With Text Property you can refer this might be it will help you.
https://xamarincodingtutorial.blogspot.com/2019/05/step-to-create-imagebutton-with-text.html

how to open url webview in xamarin.form

I want to open this url(http://localhost:8080/) when application is launched. Can any one please help i'm new in xamarin And my MainPage.xaml is :
<?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:App3"
x:Class="App3.MainPage">
<StackLayout>
<!-- Place new controls here -->
<Label Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
<WebView Source="http://localhost:8080/" VerticalOptions="CenterAndExpand"/>
</StackLayout>
</ContentPage>
What URL are you trying to open? Note that localhost on your device means that you want to show a webpage that is hosted on your device. If you are trying to show a webpage hosted on your development machine, please figure out the network address that is reachable from your device. It will probably start with 192.168.x.x or 10.x.x.x.

XAML Ellipse not working

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>

Viewcell XAML + CS throws Build action 'Page' is not supported error

I am trying to link my XAML ViewCell with the c# counterpart and use it with listview.
WeatherCell.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ViewCell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Name="cell"
x:Class="UI.WeatherCell">
<ViewCell.View>
<StackLayout Orientation="Vertical" Padding="10">
<Label Text="WeatherCell"
x:Name="TempLabel"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Label Text="WeatherCell"
x:Name="LocationLabel"
VerticalOptions="Center"
HorizontalOptions="Center" />
</StackLayout>
</ViewCell.View>
</ViewCell >
WeatherCell.cs
namespace UI
{
public partial class WeatherCell : ViewCell
{
public WeatherCell()
{
InitializeComponent();
}
}
}
Referred in MainPage.cs as follows
this.WeatherListView.ItemsSource = Weather.Weather.DataFactory.genForecast();
this.WeatherListView.ItemTemplate = new DataTemplate(typeof(WeatherCell));
While building I get error as
'Page' is not supported by the specific combination of the project's targets. \WeatherCell.xaml.
My guesss was x:Class="UI.WeatherCell" will link both the xaml and cs. What am I doing wrong?
Changing build action for WeatherCell.xaml fixed the problem.
it has to be set to EmbeddedResource
Build Action property can be found in file properties context menu.
Right Click the xaml file and click Properties.
Under Properties select Embedded Resource.
Rebuild your project.