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

How to remove gaps in the splash with 9 patch images?

$
0
0

Dear,

After update my xamarin forms android app to use targetSdkVersion 27 (I don't remember surely but think that before was 16) my splash screen is shown with two rectangles and I don't found the cause, someone already dealed with this issue?


Resource file or ResorceDictionary for storing colors

$
0
0

I am looking to keep custom color hex codes in either a .resx file or a resourceDictionary (.xaml) file so I can reuse it between views in my app. I know I can use resource files with strings for texts but it throws an error if I try the same way to pull a string containing the hex code for colors, it throws an error. What's the best way to do this?

Here's what I have in xml:

    <!--This doesn't work-->
    <StackLayout BackgroundColor="{x:Static CustColors.JsBlue}">

        <!--This works-->
        <Label Text="{x:Static resx:Texts.MainTitle}" 
               HorizontalOptions="Center"/>

    </StackLayout>

TapGestureRecognizer problems

$
0
0

I am new to mobile development, but have been a C# developer for years. I'm creating my first Xamarin Forms app and I cannot seem to grasp how to implement the TapGestureRecognizer. I have a "SignUp" label on the first page of my app. In its xaml I have the following code:

<Label.GestureRecognizers>

</Label.GestureRecognizers>

in my code behind cs page I have the following method:
void SignupGestureRecognizerTapped(object sender, EventArgs e)
{
Navigation.PushAsync(new signup());
}

The Xamarin forms previewer displays an error message saying there is no method "SignupGestureRecognizerTapped" on type "login". I'm assuming it's telling me it can't find the method that corresponds to the one listed in the xaml. I have rebuilt the solution multiple times and it will not deploy to the emulator without crashing.
Is there something I'm leaving out?
Thanks.

G

P.S.
I originally posted this in the Android forum and someone suggested I make the method in the code behind Public async with await in the call to the new page so that it looks like this:
Public async void SignupGestureRecognizerTapped(object sender, EventArgs e)
{
await Navigation.PushAsync(new signup());
}
This didn't seem to help. The method in my code behind is still not being seen.

UI code in both xaml and c# files

$
0
0

I was wondering if it was possible to have code for a content page where I could have static views made in the xml and have dynamically created views in the C# file. Most examples of writing UI content page code either has all the code in xaml or in c#, but I want to use C# to add views into layouts that already exist without overwriting the existing code.

Get UIBarButtonItem from ToolbarItem

$
0
0

So, I have a UIAlertController action sheet that I display using iOS-only code in my cross-platform Xamarin.Forms app. The action sheet is displayed when a Xamarin.Forms.ToolbarItem is tapped by the user. When on iPad, the UIAlertController containing the action sheet needs to have its UIPopoverPresentationController.BarButtonItem set to the menu item that caused it to appear, or I have to manually specify a location on screen where I want the action sheet to appear.

Is there no way of converting a Xamarin.Forms.ToolbarItem into its corresponding UIBarButtonItem?

I've tried for hours by intercepting calls to PageRenderer and NavigationRenderer to no avail, since the ToolbarItems properties of the respective native views are never set. I can see the Xamarin.Forms.ToolbarItems I provided at Xamarin.Forms.Page construction, however. I cannot use Platform.GetRenderer() as it requires a VisualElement, which Xamarin.Forms.ToolbarItem doesn't implement.

I also looked at Xamarin.Forms.Platform.iOS.ToolbarItemExtensions.ToUIBarButtonItem, which gives me a proper UIBarButtonItem from a Xamarin.Forms.ToolbarItem, but the provided item is a new such, and has no correspondence on screen. Using the returned item as a value for UIPopoverPresentationController.BarButtonItem causes the application to crash.

Any other ideas?

Can I send a value to my Webapi not to be stored in database but as a parameter to return data

$
0
0

Hi All,

So I am using web api to post data to a database on the server.. work great easy to understand how its working...
But in this case.. the users want to be able to send and Id via their devices and have that Id get processed and
return a value back to a list display on the device...

So and web api get.. but with a parameter... Is there some example I can follow showing how this can be done...
I am sure this is more a question for web api people

But I wanted to check here first.. because I was not sure how to refresh the page on the device if this can be done.

Thanks.

Map.IsShowingUser="True" crashes on Android 7 with Xamarin.Forms.Maps released on 1/3/2019

$
0
0

Even though updated Xamarin.Forms.Maps to the newest version(3.4.0.1009999) and provided the following permissions in AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

The app still crashes when set IsShowingUser="True" on my Samsung Galaxy Note 5

     <maps:Map x:Name="map" HeightRequest="400" HorizontalOptions="FillAndExpand" IsShowingUser="True" />

If remove IsShowingUser="False". The map can be shown

Any solution?

MasterDetailPage does not show Master

$
0
0

I create a new application with a xaml form:

<?xml version="1.0" encoding="utf-8" ?>

<MasterDetailPage.Master>
    <ContentPage Title="Menu">
        <StackLayout>
            <Label Text="Menu"></Label>
        </StackLayout>
    </ContentPage>
</MasterDetailPage.Master>

<MasterDetailPage.Detail>
    <ContentPage>
        <StackLayout>
            <Label Text="Detail"></Label>
        </StackLayout>
    </ContentPage>
</MasterDetailPage.Detail>

When i run show only de Detail.


InitializeComponent does not exist in the current context error

$
0
0

Hi,

The error CS0103 (The name 'InitializeComponent' does not exist in the current context) has started appearing after doing a build of our Xamarin Forms solution. The build, however, appears to have succeeded in spite of this error message?

This started happening after adding the first XAML ContentPage to the PCL project. If I remove the XAML ContentPage then the error disappears.

I've tried installing the latest Alpha channel update on both my Windows (Visual Studio) machine and my Mac build host but it hasn't made any difference.

Please advise ASAP as we would like to use XAML for our ContentPages but may have to revert to using C# code to build the UI if the XAML approach is not viable.

Regards,
Andy

Recommend beautiful template

$
0
0

Hi All

I am would like to build a mobile app on Xamarin and back-end on web application. Could you share me some of beautiful template that I can buy for my mobil app, and also back-end web-app?

Thanks in advance

How to Get full File Path of Image and Upload it to server

Bound property not yet set when xaml tag requires it

$
0
0

Hi there, I'm trying to use code from the video example found here. However that example directly specifies the video source in the xaml, and I'm trying to bind that value. Unfortunately it seems by the time the property on the video control is set from the xml, the binding is not yet available. It seems there is something I'm missing about setup and binding order. Can anyone help me understand what I'm doing wrong here? More detail follows:

This uses a simple View, with a custom control (with an exported renderer), with it's "Source" set to a bound value:

<?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:videoplayer="clr-namespace:BunAndBuneeTV.Controls.VideoPlayer"
             x:Class="BunAndBuneeTV.Views.VideoPlayerView">
    <videoplayer:VideoPlayer Source="{Binding EpisodePath}" AutoPlay="true"/>
</ContentPage>

The binding is to an equally simple viewmodel:

public class VideoPlayerViewModel :
    ViewModelBase
{
    private Episode episode;

    public string EpisodePath => (episode != null) ? episode.Path : string.Empty;

    #region ViewModelBase overrides
    public override async Task InitializeAsync(object navigationData)
    {
        episode = navigationData as Episode;

        await base.InitializeAsync(navigationData);
    }
    #endregion
}

The custom control includes the expected Source property (with a converter):

public class VideoPlayer : View, IVideoPlayerController
{
    // Lots of excluded detail..

    // Source property
    public static readonly BindableProperty SourceProperty =
        BindableProperty.Create(nameof(Source), typeof(VideoSource), typeof(VideoPlayer), null);

    [TypeConverter(typeof(VideoSourceConverter))]
    public VideoSource Source
    {
        set { SetValue(SourceProperty, value); } // This appears to only be called once, before the BindingContext is set
        get { return (VideoSource)GetValue(SourceProperty); }
    }
}

And finally the renderer uses Source in OnElementPropertyChanged:

public class VideoPlayerRenderer : ViewRenderer<VideoPlayer, UIView>
{
    // Lots of excluded detail..

    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs args)
    {
        base.OnElementPropertyChanged(sender, args);

    if (args.PropertyName == BnBVideoPlayer.SourceProperty.PropertyName)
        {
    var source = Element.Source;
    // Problem! source is null!
        }       
    }
}

I use a typical NavigationService pattern, so I'll save you the details of that, but fundamentally the order of execution here is:

var page = Activator.CreateInstance(pageType) as Page;
ViewModelBase viewModel = container.Resolve(viewModelType) as ViewModelBase;
page.BindingContext = viewModel;

if (CurrentApplication.MainPage is NavigationPage navigationPage) // This is true
{
    await (page.BindingContext as ViewModelBase).InitializeAsync(navigationData);
    await navigationPage.PushAsync(page);
}

Now the OnElementPropertyChanged gets called during the page.BindingContext = viewModel;, by which time the bindingcontext's InitializeAsync hasn't been called. I could await the InitializeAsync before setting the view's BindingContext, but then when the application starts up an exception is thrown because the first page isn't set up yet (because of delay waiting to set it up)-"NSInternalInconsistencyException Reason: Application windows are expected to have a root view controller at the end of application launch". How is this usually resolved? I can't imagine it's unusual having a requirement to wait for bindings to complete on the first page of an application? Does everyone just have a dummy static page that requires no bindings or something?

Thanks in advance :smile:

How to Solve {StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.

$
0
0

I want to send some data to API through POST method.While Debugging instead of json output I am getting this. So unable to deserialize json object. Any suggestion please..........

{StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Cache-Control: no-cache, private Connection: close Date: Fri, 11 Jan 2019 05:10:42 GMT Server: Apache Transfer-Encoding: chunked Vary: Accept-Encoding,User-Agent X-Android-Received-Millis: 1547183571964 X-Android-Response-Source: NETWORK 500 X-Android-Selected-Protocol: http/1.1 X-Android-Sent-Millis: 1547183571710 X-Powered-By: PHP/7.2.6 Content-Type: text/html; charset=UTF-8 }} xamarin forms

This is my c# code.

public class StatusView
{
    public string status { get; set; }
}

class AddBillFun
{
    public async static Task<StatusView> AddBillData(string transaction_date1, string billing_date1, string vehicle_id1, string customer_id1, string fuel_id1
                                               , string fuel_unit_id1, string fuel_price_id1, string price_per_unit1, string quantity1, string amount1
                                               , string recieved_amount1, string advanced_amount1, string net_amount1, string _status1, string station_id1)
    {

        StatusView statusCheck = new StatusView();
         Uri uri = new Uri(Constants.Bills_URL);
        var postData = new List<KeyValuePair<string, string>>
            {
                new KeyValuePair<string, string>("transaction_date",transaction_date1),//"2018-10-05 12:16:11"
              new KeyValuePair<string, string>("billing_date",billing_date1 ),//"2018-10-05"
                new KeyValuePair<string, string>("vehicle_id",vehicle_id1),//"1"
                new KeyValuePair<string, string>("customer_id", customer_id1),//"1"
                new KeyValuePair<string, string>("fuel_id",fuel_id1),//"1"
                new KeyValuePair<string, string>("fuel_unit_id",fuel_unit_id1 ),//"1"
                new KeyValuePair<string, string>("fuel_price_id",fuel_price_id1 ),//"2"
                new KeyValuePair<string, string>("price_per_unit",price_per_unit1 ),//"70"
                new KeyValuePair<string, string>("quantity", quantity1),//"10"
                new KeyValuePair<string, string>("amount",amount1 ),//"700"
                new KeyValuePair<string, string>("received_amount",recieved_amount1 ),//"0"
                new KeyValuePair<string, string>("advance_amount", advanced_amount1 ),//"0"
                new KeyValuePair<string, string>("net_amount",net_amount1 ),//"700"
                new KeyValuePair<string, string>("status",_status1 ),//"success"
                new KeyValuePair<string, string>("station_id",station_id1 ),//"1"

            };

        HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Post, uri);
        req.Content = new FormUrlEncodedContent(postData);

        using (HttpClient client = new HttpClient())
        {
            var response = await client.SendAsync(req);

            var content = await response.Content.ReadAsStringAsync();

            statusCheck = JsonConvert.DeserializeObject<StatusView>(content);
        }

        return statusCheck;

    }
}

ZXingScannerPage

$
0
0

Hi to all,
I am using ZXingScannerPage to scan barcodes.
I have a xaml contect page (myContentPage.xaml).
In code behind, I added ZXingScannerPage in a content page and after scan a popup arrears. So far so good.
My problem is that I do not know how I can put ZXingScannerPage in my contect page (myContentPage.xaml), and after scan, to update labels within myContentPage.xaml.
Do i have to change ZXingScannerPage to something else?

Thanks in advance

Background Color Transparent is not working in GroupHeaderTemplate of Listview in Xamarin Forms iOS

$
0
0

I have set background image for whole application,
In Listview, GroupHeaderTemplate Background color set 'Transparent', but it displays white only.
In Android it's working properly. Anyone knows the solution ?


Toolbaritems, I have set font awesome text icon, it's not display in iOS.

$
0
0

I have set Font awesome icon in Text of Toolbaritems, It was working properly.
But after set Navigation bar Property using : On<Xamarin.Forms.PlatformConfiguration.iOS>().EnableTranslucentNavigationBar();
For Transparent Navigation bar, but now Icons are not displaying, Question mark shows.

ERROR WITH LATEST NUGET v2.5.0.77 "Xamarin.Forms.Build.Tasks.GetTasksAbi" task could not be loaded

$
0
0

I just got latest stable 2.5.0.77107 and I can't compile anymore

[myUser]\packages\xamarin.forms\2.5.0.77107\build\netstandard1.0\Xamarin.Forms.targets(55,3): error MSB4062: The "Xamarin.Forms.Build.Tasks.GetTasksAbi" task could not be loaded from the assembly [myUser]\.nuget\packages\xamarin.forms\2.5.0.77107\build\netstandard1.0\Xamarin.Forms.Build.Tasks.dll.  Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

I replaced my user path with [myUser]

it looks like this bug exists since October in the pre-release:

https://bugzilla.xamarin.com/show_bug.cgi?id=60293

Is it possible to load resx file on Runtime dynamically?

$
0
0

If i download resx file as string from remote, is it possible to load on Runtime dynamically? Similar to LoadXaml option that we can load xaml from string? there is ResourceLoader but I am not sure if it related and if yes, how to use it?

How to remove the selected item from FlowListView?

$
0
0

I need to remove the selected picture when clicks a cross image. For that, I added a cross image on top of the image and added the tapped event. I am showing the images in FlowListView.

MainPage.xaml

<flv:FlowListView 
        FlowColumnCount="3" 
        x:Name="listItems" 
        SeparatorVisibility="None"
        HasUnevenRows="false" 
        RowHeight="100" >
        <flv:FlowListView.FlowColumnTemplate>
            <DataTemplate>

                <StackLayout
                    Orientation="Vertical">

                    <Image 
                        Source="ic_close.png"
                        HeightRequest="20"
                        WidthRequest="20">
                        <Image.GestureRecognizers>
                            <TapGestureRecognizer
                            Tapped="RemoveImage"
                            NumberOfTapsRequired="1" />
                        </Image.GestureRecognizers>
                    </Image>

                    <Image 
                        AbsoluteLayout.LayoutFlags="All" 
                        HeightRequest="100" 
                        AbsoluteLayout.LayoutBounds="0,0,1,1" 
                        Source="{Binding .}"  
                        Aspect="AspectFill" 
                        HorizontalOptions="FillAndExpand">
                    </Image>
                </StackLayout>
            </DataTemplate>
        </flv:FlowListView.FlowColumnTemplate>
    </flv:FlowListView>

MainPage.xaml.cs

 public partial class MainPage : ContentPage
 {
    List<string> _images = new List<string>();
    public MainPage()
    {
        InitializeComponent();
    }

    protected override void OnAppearing()
    {
        base.OnAppearing();

        MessagingCenter.Subscribe<App, List<string>>((App)Xamarin.Forms.Application.Current, "ImagesSelected", (s, images) =>
        {
            listItems.FlowItemsSource = images;
            _images = images;
        });
    }

    protected override void OnDisappearing()
    {
        base.OnDisappearing();
        MessagingCenter.Unsubscribe<App, List<string>>(this, "ImagesSelected");
    }

    public void RemoveImage(Object sender, EventArgs args)
    {
        // How I can remove the selected image from the FlowListView
    }
}

Anybody, please suggest a way to remove that image from FlowListview?

What is the best approach to display to the user actions that he can do for the ListView items?

$
0
0

Hi guys, I'm implementing a ListView in Xamarin.Forms , I just implemented behaviors for when the items are tapped following this tutorial: https://blog.xamarin.com/turn-events-into-commands-behaviors/ but I also want that the user can do another actions for each item on the listview besides tapping. I drawed below how I imagined this could be done, an Image that when I click it pops a MenuList ,how can I implement this on MVVM?

Viewing all 91519 articles
Browse latest View live


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