Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all 91519 articles
Browse latest View live

Getting an Error: The type name 'GeneratedCodeAttribute' could not be found in the namespace

$
0
0

Hi, I have been working on an android project using Xamarin.forms and after some successful builds, came across this error:

Severity    Code    Description Project File    Line    Suppression State Error CS1069  The type name 'GeneratedCodeAttribute' could not be found in the namespace 'System.CodeDom.Compiler'. This type has been forwarded to assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' Consider adding a reference to that assembly. SentimentAnalyzer.Android C:\Users\shubh\source\repos\SentimentAnalyzer\SentimentAnalyzer\SentimentAnalyzer.Android\Resources\Resource.Designer.cs 18  Active

To solve this, I tried to install: > Microsoft.CodeDom.Providers.DotNetCompilerPlatform but ended up having another error:

Install-Package : NU1202: Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform 2.0.0 is not compatible with monoandroid81 (MonoAndroid,Version=v8.1). Package 
Microsoft.CodeDom.Providers.DotNetCompilerPlatform 2.0.0 supports: net45 (.NETFramework,Version=v4.5)`.

I tried changing target framework for compiling to lower versions of Android, still having the similar issue. Please help.


Failure [INSTALL_FAILED_VERSION_DOWNGRADE], can not deploy Android app

$
0
0

Hello, in my solution, I can not run the project on my Android phone. Can not deploy the solution because of the error : Failure [INSTALL_FAILED_VERSION_DOWNGRADE]. How can I solve it?

DTS, ODTC are not allowed for Package

$
0
0

I'm trying to play a video on my xamarin app but I keep getting this message:

DTS, ODTC are not allowed for Package

I researched it and not finding anything that tells me what permission I'm needing

all I'm doing is playing a video from a url and I have internet permission setup for android so I'm lost

ContentControl in Xamarin Forms?

$
0
0

Is there a way to use ContentControl in Xamarin Forms?

master detail menu page, link text not displayed

$
0
0

I create new xamarin forms project with master detail template.

When I try to run the project using release configuration the link text in drawer is not displayed but when I using debug configuration, the link text is displayed correctly.

is it a bug or I miss some setting?

How to hide tab bar on push in Xamarin.forms Tabbed Page?

$
0
0

I need to hide the bottom tab bar when pushing to a new page from a tabbed page.
Any solution?

master detail menu page, link text not displayed

$
0
0

I create new xamarin forms project with master detail template.

When I try to run the project using release configuration the link text in drawer is not displayed but when I using debug configuration, the link text is displayed correctly.

is it a bug or I miss some setting?

How to update progressbar from customwebview renderer in xamarin forms for android?

$
0
0

I'm new to Xamarin Forms and I'm struggling on how to update a ProgressBar from a WebView using a custom renderer for the webview.

In android you can do something like this, with the progressbar and webview that are in the main_layout.xml

public class MainActivity extends Activity {

    private ProgressBar progressBar;
    private WebView webView;    

    @Override
    protected void onCreate(Bundle savedInstanceState) {     
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_layout);

        progressBar = (ProgressBar) findViewById(R.id.progress);
        webView = (AdvancedWebView) findViewById(R.id.webView);
        // webview initialisation
        webView.setWebViewClient(new WebViewClient(this) {
            @Override
            public void onPageFinished(WebView view, String url) {
                // update progressbar
                progressBar.setVisibility(View.GONE);
            }
        });
    }
}

In Xamarin Forms I have this layout in MainPage.xaml in the shared project

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="MainPage"
NavigationPage.HasNavigationBar="False">

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <ProgressBar
        x:Name="progress"
        Grid.Row="3"
        HorizontalOptions="FillAndExpand"
        Progress="0"
        VerticalOptions="Center" />

    <WebView
        x:Name="webview"
        Grid.Row="0"
        Grid.RowSpan="4"
        Grid.Column="0"
        HorizontalOptions="FillAndExpand"
        IsVisible="False"
        Source="URL"
        VerticalOptions="FillAndExpand" />

</Grid>

public partial class App : Application
{
    public App ()
    {
        InitializeComponent();

        MainPage = new MainPage(); 
    }
}

And this custom webview render for android in the android project

[assembly: ExportRenderer(typeof(WebView), typeof(CustomWebviewRenderer))]
namespace MyApp.Droid
{
    public class CustomWebviewRenderer : WebViewRenderer
    {
        private readonly Context context;

        public CustomWebviewRenderer(Context context) : base(context)
        {
            this.context = context;
        }

        protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
        {
            base.OnElementChanged(e);
            var formsWebView = e.NewElement as Xamarin.Forms.WebView;

            if (formsWebView != null)
            {
                var webView = Control as Android.Webkit.WebView;
                webView.SetWebViewClient(new CustomWebViewClient());           
                webView.Settings.LoadWithOverviewMode = true;
                webView.Settings.UseWideViewPort = true;
                SetNativeControl(webView);
            }
        }

        private class CustomWebViewClient : WebViewClient
        {
            public override void OnPageFinished(Android.Webkit.WebView view, string url)
            {
                // how to update progressbar?
                base.OnPageFinished(view, url);
            }

            public override void OnPageStarted(Android.Webkit.WebView view, string url, Bitmap favicon)
            {
                base.OnPageStarted(view, url, favicon);
            }

            public override bool ShouldOverrideUrlLoading(Android.Webkit.WebView view, IWebResourceRequest request)
            {
                return base.ShouldOverrideUrlLoading(view, request);
            }
        }
    }
}

How can I update the ProgressBar that I have in my MainPage.xaml from the OnPageFinished in the CustomWebviewRenderer class to show the webpage has finished loading? Should I use the MainActivity.cs in the Android project?

Can someone point me in the right direction on how to solve this?


How to calculate viewcell height?

$
0
0

Can calculate viewcell height? Sorry, my bad english.

Plugin multilingual, resx file??

$
0
0

Hola, I hade create a resx file in my project and Don't know why its not showing the table to fill , its showing this code

``<?xml version="1.0" encoding="utf-8"?>
<root>
    <resheader name="resmimetype">
        <value>text/microsoft-resx</value>
    </resheader>
    <resheader name="version">
        <value>2.0</value>
    </resheader>
    <resheader name="reader">
        <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    </resheader>
    <resheader name="writer">
        <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    </resheader>
</root>
``

UWP - Cannot resolve Assembly or Windows Metadata file

$
0
0

Hi All,

Everything was rolling along smoothly until a few days ago when UWP all of a sudden stopped building after pulling a new version from VSTS (git) with the errors:

  • Cannot resolve Assembly or Windows Metadata file 'Type universe cannot resolve assembly: X.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.'
  • Could not copy the file "obj\x86\Debug\MainPage.xbf" because it was not found.
  • Could not copy the file "obj\x86\Debug\App.xbf" because it was not found.
  • Could not copy the file "obj\x86\Debug\X.Mobile.UWP.xr.xml" because it was not found.

I have a solution structure of the following:

  • X.Core (.NET Standard class library)
  • X.Mobile (.NET Standard PCL)
  • X.Mobile.UWP (UWP specific project)

UWP references Mobile, and Mobile references Core (Core is also referenced by a web API project).

The commit that I pulled from source control did not have any changes to the X.Mobile.UWP .csproj file.

Things I have tried:

  1. The obligatory clean and rebuild.
  2. Delete all obj and bin folders for the entire solution.
  3. Remove and re-add all references in the .UWP project.
  4. Upgrade Xamarin.Forms to the latest stable (3.1.0.637273).
  5. Remove and re-add X.Core reference in the X.Mobile project.
  6. Delete C:\Users\%username%.nuget folder.
  7. Update Microsoft.NETCore.UniversalWindowsPlatform to the latest stable (6.1.5).
  8. Change the target version to all available versions - we've been running on build 16299 for several months.

And I've been beating my head against this problem on and off for days now. Android and iOS projects build just fine, which is ironic considering UWP has been our most stable platform. Anyone have any insight?

EDIT:
After adding a reference to X.Core to the X.Mobile.UWP project directly, I can compile. This shouldn't be the answer though since the UWP project never directly references the Core project.

Custom WebView issue on iOS

$
0
0

I have implemented a custom WebView and facing issues with the iOS custom renderer implementation. I use Prism for navigation, and sets the uri property of the Custom WebView in the OnNavigatingTo method.

My issue is that when the OnElementChanged method of my iOS CustomRenderer is executed the Uri property is null. This is not an issue with the Android implementation. If i set the SourceUrl property in the constructor of my viewmodel for testing, it works fine.

Any help would be greatly appreciated!

Here is my code:

Contentpage:

<StackLayout>
    <local:CustomWebView x:Name="Browser" Uri="{Binding SourceUrl}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />       
</StackLayout>

ViewModel:

public class DocumentPageViewModel : ViewModelBase
{
public DocumentPageViewModel(INavigationService navigationService) : base(navigationService)
{
// This works fine
// SourceUrl = "someurl";
}

    private string _sourceUrl;
    public string SourceUrl
    {
        get { return _sourceUrl; }
        set { SetProperty(ref _sourceUrl, value); }
    }

    private string _title;
    public string Title
    {
        get { return _title; }
        set { SetProperty(ref _title, value); }
    }

    public override void OnNavigatingTo(NavigationParameters parameters)
    {
        var url = parameters["url"].ToString();
        var title = parameters["title"]?.ToString();

        Title = title;
                SourceUrl = url;
    }
}

CustomWebView:

public class CustomWebView : WebView
{
    public static readonly BindableProperty UriProperty = BindableProperty.Create("Uri",
            typeof(string),
            typeof(CustomWebView),
            defaultBindingMode: BindingMode.OneWay);

    public string Uri
    {
        get 
        {
            var val=(string)GetValue(UriProperty); 
            return val; 
        }
        set { SetValue(UriProperty, value); }
    }
}

CustomRenderer iOS:

[assembly: ExportRenderer(typeof(CustomWebView), typeof(CustomWebViewRenderer))]

namespace ByggeplassAssistenten.iOS.CustomRenderers
{
public class CustomWebViewRenderer : ViewRenderer<CustomWebView, UIWebView>
{
public CustomWebViewRenderer()
{
}

    protected override void OnElementChanged(ElementChangedEventArgs<CustomWebView> e)
    {
        base.OnElementChanged(e);

        if(Control == null)
        {
            SetNativeControl(new UIWebView());
        }

        if (e.OldElement != null)
        {
            // unhook event handlers etc here
        }

        if(e.NewElement != null)
        {
            var customWebView = Element as CustomWebView;

    //HERE IS MY ISSUE: customWebView.Uri is always NULL

            if(customWebView.Uri != null)
            {
                Control.LoadRequest(new NSUrlRequest(new NSUrl(customWebView.Uri)));

                Control.ScalesPageToFit = true;
            }
        }
    }
}

}

Properties of BindingContext are not set on Xamarin.Forms project

$
0
0

Hi,

I am trying to set BindingContext of my ContentPage.

As an example I tried Hanselman.Forms project on Github and when I debugged the MenuPage.xaml.cs, BindingContext is successfully set with the following lines :

BindingContext = new BaseViewModel
{
Title= "Hanselman.Forms",
Subtitle="Hanselman.Forms",
Icon = "slideout.png")
};

As seen here:
us.v-cdn.net/5019960/uploads/editor/cc/wg85o6dxqu24.png

In this example BaseViewModel is a class contained in Refactored.MvvmHelpers project on Github.

But when I try the same thing on my project BindingContext properties are not set. As seen here:
us.v-cdn.net/5019960/uploads/editor/4g/f3ijt96n7ioe.png

Also when I look at BindingContext of Hanselman.Forms project via a watch, I can see public properties. As you can see here:
us.v-cdn.net/5019960/uploads/editor/of/jk7zf8a8qwqj.png

But when I try to look at BindingContext in my project with a watch this is what I see
us.v-cdn.net/5019960/uploads/editor/c5/bwfdh54eq92u.png

I don't know what could be causing this strange behaviour.

As extra info:

Both solutions' core projects are .NET Standard Library v2.0.
Both solutions' Xamarin.Forms Nuget packages are the latest version.

Thanks in advance.

Note: I had to strip my image links from https to avoid "You have to be around for a little while longer before you can post links." error. Sorry for bad format.

OnAppearing() not working anymore

$
0
0

I don't know what else to mention besides this but OnAppearing isn't firing anymore. I am using TabbedPage but I was using TabbedPage before when OnAppearing was working as well.

Anyways here is what I am trying to achieve and maybe there may be another way to implement it.

The master page is a tabbed page containing Page C. Now Page C is an empty carousel page in which its OnAppearing() populates it like so:
Children.Add(new PersonPage()) //run 10 times so Page C is now a carousel page with 10 pages

So now what I am trying to do is when the user is on the 8th page (the 8th PersonPage) in the carousel page, add more pages to the carousel page so that the user does not reach the end of the carousel page. An infinite scrollable carousel page.

I basically added a flag to the 8th page and in the PersonPage() onAppearing(), checked whether the flag is set and then called:
parent.Children.Add(new PersonPage())

This was working but it isn't anymore. It seems to be because the PersonPage() OnAppearing() isn't firing anymore. I tested this by calling a DisplayAlert() which didn't show up.

Has anyone done anything similar?

ExpandableView nuget package


in app purchases Restore puchases

$
0
0

Hi,

I use Xamarin Forms and the Plugin.InAppBilling plugin.
Do I have to run the restore the purchases method (LoadItemsAsync()) when the app starts at the first time or just when they press the 'Restore purchases' button?

And also when they try to buy the product how can I check if they ever bought it before?

Many thanks

Data from local db is getting deleted on resuming network, without any explicit code to delete data

$
0
0

App supports offline capabilities and all data is being fetched from and saved to local SQL Lite DB. On resuming network, if the connectivity is very poor, intermittently the data from local db gets deleted. There is no explicit code to delete the data from local DB.

Has anyone of you encountered this problem? If yes, please suggest steps to avoid this

Refresh ContentView

$
0
0

I have a contentview which is using a ControlTemplate. However the ControlTemplate has labels which have bindings. These labels values change. The ContentView however doesn't change. I need a way to refresh my ContentView.

            <ContentView ControlTemplate="{StaticResource SelectTransportZiel}"/>

Await post async always throw null exception

$
0
0

Using xamarin forms 3

I Have an HTTP post request and if the flow goes async a null exception occurs in

await.PostAsync. But if I change the async Flow to sync using wait, the value is returned without any problem or PostAsync().Result as well.

Here is a code snippet of post I use.

Note that I call the ReturnAccountsAsync in a loop.

public async Task<List<string>> ReturnAccountsAsync(List<FavItem> list, int LanguageId)
{
    this.list = list;
    var client = new HttpClient();

    var jasonData = JsonConvert.SerializeObject(list);
    StringContent content = new StringContent(jasonData, Encoding.UTF8, "application/json");

    try
    {
        var APiUrl = string.Format(Constants.RestURL_PostReturnTweets + "?LanguageId={0}", LanguageId);

        var response= await client.PostAsync(APiUrl, content);

        if (response.IsSuccessStatusCode)
        {

            var content2 = response.Content.ReadAsStringAsync().Result;
            accounts = JsonConvert.DeserializeObject<List<string>>(content2);
        }
    }
    catch (Exception)
    {

    }

    return accounts;
}

in the ViewModel the call of ReturnAccountsAsync is awaited

     private async Task GetTeamsAccountsAsync()
    {
        var TeamsIds = await BlobCache.LocalMachine.GetObject<List<int>>("FavouriteTeams");
        List<string> Tabs = new List<string>() {App.LabelsDictionary["Favourites"],App.LabelsDictionary["Official"] };

        foreach (var Tab in Tabs)
        {
            foreach (var TeamId in TeamsIds)
        {
            _favouriteItems.Add(new FavItem { Id = TeamId, IsCompetition = false });
        }

            //teamsAccounts = await socialMediaTweets.ReturnAccountsAsync(new List<FavItem>(), App.LanguageId);

                teamsAccounts = Tab == Tabs.Last() ? await socialMediaTweets.ReturnAccountsAsync(new List<FavItem>(), App.LanguageId) : await socialMediaTweets.ReturnAccountsAsync(_favouriteItems, App.LanguageId);


            await InitTweetsAsync(teamsAccounts, Tab);
    }

The call of GetTeamsAccountsAsync() in the constructor

        public SocialMediaTabbedPageViewModel(ISocialMediaTweets socialMediaTweets)
        {
            this.socialMediaTweets = socialMediaTweets;
            TweetSelected = new Command(_TweetSelected);
            Task.Run(async()=>await GetTeamsAccountsAsync() );
        }

Bindable properties on custom control not working

$
0
0

Hi,

I dabbled with Xamarin in the past, about 4 years ago, but for the sake of this post, lets say I'm a total newb, which I essentially am.

I am trying to create a page in which I want the same set of views rendered multiple times. So I decided to create a composite control. Mine is very simple, pretty much just a grouping of a label, a progressbar, a button, and another label. I named the control FractionProgressbar. Probably not the best name for it, but let's worry about that another time.

I seem to be missing some vital piece of fundamental knowledge. My composite control has three BindableProperty-members: Label, Total and Current. The only one I manage to get working is Label, Total and Current is always 0 (their default value) no matter what I set them to in the MainPage.xaml or MainPage.xaml.cs.

If anyone has any insight here, Id be incredibly grateful!

I've searched for information about this on the forum but either I can't find it, or I found it but didn't realize it pertained to my issue.

P.S. I am not allowed to post links to I have replaced the schema links in the xaml-files with [LINK TO SCHEMA]...

FractionProgressbar.xaml.cs

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace EcoEater.Controls
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class FractionProgressbar : ContentView
    {
        public static readonly BindableProperty LabelProperty = BindableProperty.Create(
            propertyName: "Label",
            returnType: typeof(string),
            declaringType: typeof(FractionProgressbar),
            defaultValue: "",
            defaultBindingMode: BindingMode.TwoWay
            );

        public static readonly BindableProperty TotalProperty = BindableProperty.Create(
            propertyName: "Total",
            returnType: typeof(int),
            declaringType: typeof(FractionProgressbar),
            defaultValue: 0,
            defaultBindingMode: BindingMode.TwoWay
            );

        public static readonly BindableProperty CurrentProperty = BindableProperty.Create(
            propertyName: "Current",
            returnType: typeof(int),
            declaringType: typeof(FractionProgressbar),
            defaultValue: 0,
            defaultBindingMode: BindingMode.TwoWay
            );

        public string Label
        {
            get
            {
                return (string)GetValue(LabelProperty);
            }
            set
            {
                SetValue(LabelProperty, value);
            }
        }


        public int Total
        {
            get
            {
                return (int)GetValue(TotalProperty);
            }
            set
            {
                SetValue(TotalProperty, value);
            }
        }


        public int Current
        {
            get
            {
                return (int)GetValue(CurrentProperty);
            }
            set
            {
                SetValue(CurrentProperty, value);
            }
        }

        public double Percentage
        {
            get
            {
                return (double)Current / (double)Total;
            }
        }
        public string FractionLabel
        {
            get
            {
                return $"{Current} out of {Total}";
            }
        }

        public FractionProgressbar ()
        {
            InitializeComponent ();
            BindingContext = this;
        }
    }
}

FractionProgressbar.xaml

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="[LINK TO SCHEMA]" 
             xmlns:x="[LINK TO SCHEMA]"
             x:Class="EcoEater.Controls.FractionProgressbar">
    <ContentView.Content>
        <StackLayout>
            <Label Text="{Binding Label}" />
            <ProgressBar Progress="{Binding Percentage}" />
            <Button x:Name="plusButton"
                    Text="+"
                    FontSize="Medium"
                    FontAttributes="Bold" />
            <Label Text="{Binding FractionLabel}" />
        </StackLayout>
    </ContentView.Content>
</ContentView>

And the way I use the control is in my MainPage

MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="[LINK TO SCHEMA]"
            xmlns:x="[LINK TO SCHEMA]"
            xmlns:views="clr-namespace:EcoEater.Views"
            xmlns:controls="clr-namespace:EcoEater.Controls"                  
            x:Class="EcoEater.Views.MainPage">
    <StackLayout>
        <controls:FractionProgressbar
                    Label="Test"
                    Total="14"
                    Current="6"/>
    </StackLayout>
</ContentPage>

Mainpage.xaml.cs

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace EcoEater.Views
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class MainPage : ContentPage
    {
        public MainPage(User user)
        {
            InitializeComponent();
            BindingContext = this;
        }
    }
}

Result

The label is correct ("Test") however both the progressbar and the last label are both zeroed, even though I set Total to 14 and Current to 6 when I consume the control.

Tried posting an image of the result, apparently I am not allowed to : (

Viewing all 91519 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>