When I use a LinearGradientBrush (from the new 4.8 version of Xamarin.Forms), I get the followin error:
Autofac.Core.DependencyResolutionException: 'An exception was thrown while activating App.Modules.Loading.LoadingView.'
In the page preview in Visual Studio, it shows the page as expected. When I comment the LinearGradientBrush block, it runs fine.
Do you have any idea why this happens?
Thank you!
Best regards,
Eduardo Luczinski.
<?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="App.Modules.Loading.LoadingView">
<ContentPage.Background>
<LinearGradientBrush StartPoint="0,0"
EndPoint="0,1">
<GradientStop Color="#3B8476"
Offset="0.1"/>
<GradientStop Color="#00352B"
Offset="1.0"/>
</LinearGradientBrush>
</ContentPage.Background>
<ContentPage.Content>
<StackLayout VerticalOptions="End" HorizontalOptions="FillAndExpand">
<ProgressBar x:Name="loadingBar" VerticalOptions="End" ProgressColor="#FFFF" Progress="0.25"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
If you want to enable LinearGradientBrush in ContentPage, according to this document,you need to set up experimental flags in your target platforms projects.
On android in your MainActivity class, on ios in AppDelegate Class:
Forms.SetFlags("Brush_Experimental");
Making sure to call SetFlags() before Xamarin.Forms.Forms.Init()
The there is no problem, and it works fine.
Related
I have a TabbedPage with 3 tabs, where I want to navigate directly to the 2nd content page (TagsListPage), but still keep my Tabbed header.
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage
x:Class="BradyRfidDemo.V1.MobileApp.Views.TabbedInventoryPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:BradyRfidDemo.V1.MobileApp.Views"
Title=" SCAN PAGE"
Shell.NavBarIsVisible="false">
<local:InventoryPage />
<local:TagsListPage />
<local:Transfer />
</TabbedPage>
TagsListPage: (I removed most of the code to make it clean).
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="BradyRfidDemo.V1.MobileApp.Views.TagList"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="TAGLIST"
BackgroundColor="{StaticResource Color1}">
<ContentPage.Content>
<StackLayout >
<Frame >
<StackLayout
HorizontalOptions="Center"
Orientation="Horizontal"
VerticalOptions="Center">
<Label
x:Name="TagList"
Margin="0,10,0,0"
HorizontalTextAlignment="Center"
Text="TAGLIST" />
</StackLayout>
</Frame>
</StackLayout>
</ContentPage.Content>
</ContentPage>
So I want to access from another form content page, directly the TagsListPage, and keep my tabbed header.
If I go to the main page, I get my tabbed header, but it goes to the first page (InventoryPage)
Navigation.PushAsync(new TabbedInventoryPage());
If I go directly to the TagListPage, then I get my page, but not the tabbed structure which I need as well.
Navigation.PushAsync(new TagsListPage());
I tried a lot of different things, but nothing worked so far, and this looks like a very simple thing to do. Any help is greatly appreciated.
I would like to use CarouselView , I have installed it already (CarouselView.FormsPlugin) and I checked the packeges.config of my project and it is already there :
but still I am getting this error
The type or namespace name 'CarouselView' could not be found in the global namespace (are you missing an assembly reference?)
how can I fix this problem?
It looks like you're not using the official CarouselView. In the case of the CarouselView.FormsPlugin, the name is a CarouselViewControl.
Try it like this:
<controls:CarouselViewControl x:Name="myView">
<controls:CarouselViewControl.ItemTemplate>
<DataTemplate>
<Label Text="{Binding .}" HorizontalOptions="Center" VerticalOptions="Center"/>
</DataTemplate>
</controls:CarouselViewControl.ItemTemplate>
</controls:CarouselViewControl>
<?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:XamlTest"
xmlns:controls="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions"
x:Class="XamlTest.MainPage">
<controls:CarouselView x:Name="myView">
<controls:CarouselView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding .}" HorizontalOptions="Center" VerticalOptions="Center"/>
</DataTemplate>
</controls:CarouselView.ItemTemplate>
</controls:CarouselView>
</ContentPage>
Could you show your code in XAML?
Maybe you forgot to put the assembly / namespace?
If so try to put this in your content page tag:
xmlns:carousel="clr-namespace:CarouselView.Forms.Plugin;assembly=CarouselView.Forms.Plugin"
When you do that you can call the control with :
In my case, I had the wrong namespace in the XAML inside <ContentPage> tag. This is correct:
xmlns:controls="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions"
I'm following the hello xamarin quickstart project https://developer.xamarin.com/guides/xamarin-forms/getting-started/hello-xamarin-forms/quickstart/ for Xamarin.Forms and I'm getting a warning The private field Phoneword.MainPage.translateButon is assigned but its value is never used in the generated code files
/Demo/Phoneword/obj/Debug/Phoneword.MainPage.xaml.g.cs(46,46): Warning CS0414: The private field `Phoneword.MainPage.translateButon' is assigned but its value is never used (CS0414) (Phoneword)
Here's the 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="XamDemo.MainPage">
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness" iOS="20, 40, 20, 20" Android="20, 20, 20, 20" WinPhone="20, 20, 20, 20" />
</ContentPage.Padding>
<ContentPage.Content>
<StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Orientation="Vertical" Spacing="15">
<Label Text="Enter a Phoneword:" />
<Entry x:Name="phoneNumberText" Text="1-855-XAMARIN" />
<Button x:Name="translateButon" Text="Translate" Clicked="OnTranslate" />
<Button x:Name="callButton" Text="Call" IsEnabled="false" Clicked="OnCall" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
Why am I getting that warning? The project seems to work fine and the translate button does call a method so it is being used. I don't get the same warning for callButton which seems like it was declared in the same way. What's going on?
A translateButon field is generated in the Phoneword.MainPage.xaml.g.cs file because of the x:Name="translateButon" attribute.
This attribute gives you access to the Button element if you wanted to do anything with it in the MainPage.cs code file.
But all you need to do is done in the Xaml, namely what action should happen on click. So the warning will disappear if you remove the x:Name="translateButon" attribute.
I would like to add and remove child pages from a tabbed page in certain conditions.
However, it gives me that collection "Children" is read only .
Has anyone succeeded ?
Here is the code for TabbedPage
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
xmlns:partialViews="clr-namespace:TestTabbed.Views.PartialViews;assembly=TestTabbed"
prism:ViewModelLocator.AutowireViewModel="False"
x:Class="TestTabbed.Views.MainPage"
ItemsSource="{Binding ChannelLists}" Appearing="MainPage_OnAppearing"
Disappearing="MainPage_OnDisappearing">
<TabbedPage.ItemTemplate>
<DataTemplate>
<ContentPage Title="{Binding Name}" x:Name="mainContentPage">
<ContentPage.Content>
<OnIdiom x:TypeArguments="View">
<OnIdiom.Phone>
<partialViews:MainPhoneView />
</OnIdiom.Phone>
<OnIdiom.Tablet>
<partialViews:MainTabletView />
</OnIdiom.Tablet>
</OnIdiom>
</ContentPage.Content>
</ContentPage>
</DataTemplate>
</TabbedPage.ItemTemplate>
</TabbedPage>
Seeing your code might be helpful in case I am missing the actual issue but the following should work for you (note that you cannot directly assign a collection to the TabbedPage.Children property which is what it sounds like you are running into):
TabbedPage tab = new TabbedPage();
ContentPage page = new ContentPage();
tab.Children.Add(page);
tab.Children.Remove(page);
Where as the following will not work:
TabbedPage tab = new TabbedPage();
tab.Children = new List<Page>();
I have multiple ContentPage xaml files in my Xamarin project. I want to embed a shared piece of xaml into each ContentPage. There is nothing particularly special about the shared piece of xaml (it does't need to do anything platform specific). Shouldn't it be just as easy as embedding a tag in the xaml of the ContentPage to include the shared xaml file? Can someone point me in the right direction?
Thank you very much IdoT, It did work for me, but after adding some lines.
As this will help in making templates/custom controls/sub forms, easily added/shared across Xamarin.Forms.
Here is my full work based on your suggestion, so it can be used as is with others:
HeaderNavigationBar.xaml
<?xml version="1.0" encoding="utf-8" ?>
<StackLayout xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="App9.MVC.Views.HeaderNavigationBar"
Orientation="Horizontal"
HorizontalOptions="FillAndExpand"
Padding="10"
ackgroundColor="White">
<Button Text="Internal 1" />
<Button Text="Internal 2" />
</StackLayout>
As you can see, added:
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
and in the HeaderNavigationBar.cs, it was declared as StackLayout:
HeaderNavigationBar.cs
using Xamarin.Forms;
namespace App9.MVC.Views
{
public partial class HeaderNavigationBar : StackLayout
{
public HeaderNavigationBar()
{
InitializeComponent();
}
}
}
then for the page that will hold it/show it:
MainView.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"
xmlns:common="clr-namespace:App9.MVC.Views;assembly=App9"
x:Class="App9.MVC.Views.MainView">
<StackLayout Padding="0,0,0,20">
<common:HeaderNavigationBar>
<Button Text="External 1" />
</common:HeaderNavigationBar>
<Button Text="Test Button 1
x:Name="btnPage1"
Clicked="btnPage1_clicked" />
</StackLayout>
</ContentPage>
As you can notice, the namespace has the full path, in the MainView:
xmlns:common="clr-namespace:App9.MVC.Views;assembly=App9"
Also, you can notice that there is a button called External 1, this will also show with the
Internal buttons, as the control is a StackLayout, so it can handle adding more controls.
Screenshot:
Also for Page inside another Page:
https://github.com/twintechs/TwinTechsFormsLib
http://blog.twintechs.com/advanced-xamarin-forms-techniques-for-flexible-and-performant-cross-platform-apps-part-5-page-in-page-embedding
Again thanks goes to IdoT.
You can take the parent child of your ContentPage (for example, a StackLayout that wraps all the children), put it in an external xaml file,
and then include that component in each one of your ContentPages.
The external xaml file will be a StackLayout type, rather than a ContentPage.
Edit - added a code sample:
Let's add a header StackLayout: we add a code behind class:
public partial class HeaderNavigationBar
{
public HeaderNavigationBar()
{
InitializeComponent();
}
}
Then add the XAML code:
<StackLayout x:Class="HeaderNavigationBar"
Orientation="Horizontal"
HorizontalOptions="FillAndExpand"
Padding="10"
BackgroundColor="White">
<Image Source="burger_icon"
HorizontalOptions="StartAndExpand"
Aspect="AspectFit">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding SlideNavigationDrawerCommand}" />
</Image.GestureRecognizers>
</Image>
</StackLayout>
And finally, in the page where you want to reuse your component - add this reference:<HeaderNavigationBar />.