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

Xamarin.Forms Listview Row Height Does Not Adapt In iOS

$
0
0

I am using the code below as a custom cell in a listview. I am trying to use ForceUpdateSize() in order to update the cell of the listview whenever there is a change in the bound properties. The listview has the attribute HasUnevenRows="True". Still, when I change the name property to a long string at runtime (by using a button) in iOS, the row does not expand. But when string is long in the beginning of the application, the row has enough space to show the whole string. In Android, it seems to work fine even without the ForceUpdateSize() call. What should be done to update the height of the row to adapt to the changing content in iOS?

public class CustomCell : ViewCell
{
    public CustomCell()
    {
        Label age = new Label();
        Label name = new Label();
        StackLayout cellWrapper = new StackLayout();

        age.SetBinding(Label.TextProperty, "Age");
        name.SetBinding(Label.TextProperty, "Name");

        age.PropertyChanged += UpdateCell;
        name.PropertyChanged += UpdateCell;

        cellWrapper.Children.Add(age);
        cellWrapper.Children.Add(name);

        View = cellWrapper;
    }


    void UpdateCell(object sender, EventArgs e)
    {
        ForceUpdateSize();
    }

}

Minimum and Maximum date in Date picker

$
0
0

How set values for minimum and maximum date in datepicker in xamarin forms??

can we add placeholder for datepicker?

$
0
0

There is no property such as placeholder for datepicker,is there any alternateway for displaying text on Datepicker?
Thank you,
shreya

Screen Size in function of orientation

$
0
0

Hello,
In Android I have :
App.ScreenWidth = (int)Resources.DisplayMetrics.WidthPixels; // real pixels
App.ScreenHeight = (int)Resources.DisplayMetrics.HeightPixels; // real pixels

But in the Shared part, the values does not change in function of the screen orientation ?
Thx

Android App crashes after receiving push notification

$
0
0

Specifically, after I swipe the app off of recents, and send a notification using GCM, I receive "Unfortunately, MyApp has stopped working.". In fact, I receive this message twice for some reason, the second time comes about 10 seconds after clicking 'Ok' on the first one.

Notifications are working correctly when the app is running (foreground and background), its only after swiping it off screen do I get this error. I am able to receive notifications after I close the app if I use Baidu Push, so I know it should be possible with GCM too.

Here is the code that is causing the crash:

    [Service(Name = "my.pkg.name.MyGcmListenerService", Exported = true),
        IntentFilter(new[] { "com.google.android.c2dm.intent.RECEIVE" })]
    public class MyGcmListenerService : GcmListenerService
    {
        const string TAG = "MyGcmListenerService";

        public override void OnMessageReceived(string from, Bundle data)
        {
            // If I uncomment this try catch block, the crash doesn't happen.
            // But I still receive no notification, as there is still an exception occurring.
            // Also, the LogManager class writes the error to a .txt file, however if the
            // app is swiped off screen, it doesn't write to that file, so I don't know
            // exactly what the error is.

            //try
            //{
                CreateNotification("msg title", "new message!!!");
            //}
            //catch (Exception ex)
            //{
            //    LogManager.Instance.Log("MyGcmListenerService - OnMessageReceived ERROR: " + ex.ToString());
            //}
        }

        private void CreateNotification(string title, string message)
        {
            var intent = new Intent(Xamarin.Forms.Forms.Context, typeof(MainActivity));
            intent.AddFlags(ActivityFlags.ClearTop);
            var pendingIntent = PendingIntent.GetActivity(Xamarin.Forms.Forms.Context,
                0, intent, PendingIntentFlags.OneShot);

            var notificationBuilder = new NotificationCompat.Builder(Xamarin.Forms.Forms.Context)
                .SetSmallIcon(Resource.Drawable.icon)
                .SetContentTitle(title)
                .SetContentText(message)
                .SetAutoCancel(true)
                .SetContentIntent(pendingIntent);

            var notificationManager =
                (NotificationManager)Xamarin.Forms.Forms.Context.GetSystemService(
                    Android.Content.Context.NotificationService);

            notificationManager.Notify(0, notificationBuilder.Build());
        }

    }

IsAssignableFrom Error: System.Type does not contain a definition for 'IsAssignableFrom' and no...

$
0
0

I am attempting use IsAssignableFrom in a Xamarin Forms app, but I am being presented with the error

System.Type does not contain a definition for 'IsAssignableFrom' and no extension method 'IsAssignableFrom' accepting a first argument type of 'System.Type' could be found.

This code runs unchanged in other Windows Phone and WinRT apps.

Any ideas?

using System;
using System.Collections.Generic;
using System.Reflection.Emit;
using System.Reflection;
using System.Diagnostics;

namespace MyProject
{
    public class NavigationService : IPageNavigationService
    {
        public object NavigateToPage<T>(){
            var viewType = typeof (T);
            Debug.Assert((typeof( IPage )).IsAssignableFrom(viewType));
                    etc...

Why use Boxview control?

$
0
0

What is good things of Boxview?
Is there anything else to replace Boxview?

Customize Android Material style status bar color

$
0
0

Hi all,
I have enabled Material theme on my project with the following code, but on Android (Lollipop and Marshmallow) the top status bar (where the clock, signal, battery, etc.. are located) doesn't change; it remains always black.
I've already read lot of forums and blogs, tried lot of combination but I'm not able to get this status bar colored as I want..

MainActivity.cs
[Activity(Theme = "@style/MyTheme&quot;, Label = "MyApp", Icon = "@drawable/AppIcon&quot;, ScreenOrientation = ScreenOrientation.Portrait, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]

values-v21/style.xml
<resources>
<style name="MyTheme.Splash" parent="android:Theme.Material.Light">
<item name="android:windowBackground">@drawable/SplashScreen&lt;/item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="MyTheme" parent="android:Theme.Material.Light">
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
<item name="android:colorPrimary">@color/Brand&lt;/item>
<item name="android:textColorPrimary">@color/White&lt;/item>
<item name="android:statusBarColor">@color/BrandDark&lt;/item>
<item name="android:colorPrimaryDark">@color/BrandDark&lt;/item>
<item name="android:colorAccent">@color/Brand&lt;/item>
<item name="android:textColor">@color/Brand&lt;/item>
</style>
</resources>

values/colors.xml
<resources>
<color name="SplashBackground">#f78b2b</color>
<color name="Brand">#f78b2b</color>
<color name="BrandDark">#e47108</color>
<color name="White">#ffffff</color>
</resources>

Thanks for any help!


Button size is not exactly, BorderRadius is not working

$
0
0

left label code

xaml

<Label x:Name="presentBtn" Text="선물함" FontSize="16" HorizontalOptions="Start"  HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Grid.Column="0" BackgroundColor="#A8D2F1">

c#

presentBtn.HeightRequest = 45.0 * (double)App.ScreenWidth / 720.0;
    presentBtn.WidthRequest = 150.0* (double)App.ScreenWidth / 720.0;

.
.
.

right button code

xaml

        <Button x:Name="ticketBtn" Text="티켓충전" HorizontalOptions="End"  FontSize="16" Clicked="changeTicketCharge" Grid.Column="1" VerticalOptions="CenterAndExpand" BorderRadius="0"/>

c#

        ticketBtn.HeightRequest = 45* (double)App.ScreenWidth / 720.0;
        ticketBtn.WidthRequest = 150* (double)App.ScreenWidth / 720.0;

I make button in xamarin.form and set HeightRequest, WidthRequest.
but button size is not same to setting size.
upper image's two button is same size.
left is label with backgroundcolor, right is button.
but not same size.

and I want not rounded button. just square. but make button rounded auto.
I set BorderRadius=0, but not working.
like upper image.

plz help me

How to always get location in Background Task with Xamarin.Forms?

$
0
0

hi everybody!
I'm creating an app to using GPS and calculate distance running
How to always get current location in background task with Xamarin.Forms?
Thank you!

Signature Pad in Android via Custom Renderer approach

$
0
0

I was able to use the Custom renderer approach, in Xamarin forms to display a Signature Pad on the iOS platform.

I used this tutorial for that: https://blog.xamarin.com/using-custom-uiviewcontrollers-in-xamarin-forms-on-ios/

This is how the code looks at the moment:

In the shared code

namespace PCL.CustomControls
{
public class SignaturePad:ContentPage
{
public SignaturePad()
{
BackgroundColor = Color.Red;
}
}
}

In the iOS platform specific project: (This works great)
[assembly: ExportRenderer(typeof(SignaturePad), typeof(SignaturePad_iOS))]
namespace PCL.iOS.CustomRenderer
{
public class SignaturePad_iOS:PageRenderer
{
public override void ViewDidLoad()
{
base.ViewDidLoad();
var signature = new SignaturePadView(View.Frame);
signature.StrokeColor = UIColor.Red;
signature.SignatureLineColor = UIColor.Black;
signature.BackgroundColor = UIColor.Yellow;
View.AddSubview(signature);

    }
}

}

For Android I am trying the following, unfortunately I cannot use OnCreate, so that has put me in trouble in Xamarin Forms in this scenario:
[assembly: ExportRenderer(typeof(SignaturePad), typeof(SignaturePad_Droid))]
namespace PCL.Droid.CustomRenderer
{
public class SignaturePad_Droid:PageRenderer
{
base.OnCreate (bundle);

var signature = new SignaturePadView (this) {
    LineWidth = 3f
};
AddContentView (signature,
    new ViewGroup.LayoutParams (ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent));

}

}

Can someone help me with the Droid imp0lementation.

Thanks

AutomationId on alertBoxes

$
0
0

Is it possible to add automationId tags to alertBoxes.

This is making it difficult to write tests against android and ios without this.

await DisplayAlert("Admin User",
"Please select a client and user to impersonate.", "Ok");

Can you control the layout of tab bar items in iOS?

$
0
0

I wanted to create/modify the tab items in my XF project by perhaps changing the usual layout with the icon on top and text at the button. Is that possible?

If it is not, Can I just change the inactive tab icons? It turns gray by default but I want it to be the same as the tint color. I know this needs a custom renderer but I just don't know how as my knowledge is very limited yet.

Error CS0246: The type or namespace name could not be found. Are you missing an assembly reference.

$
0
0

Hi,

I am working on ios and android app using xamarin forms.
I am using Xamarin forms Shared project for ios and android.
Now i am facing error "Xamarin forms Error CS0246: The type or namespace name could not be found. Are you missing an assembly reference? (CS0246)".
When we build the project its working fine, but we small change in project it's always throwing above error.
I am stuck on it. I am facing same problem with ios and android.

I am tried to solve the problem but i am stuck on it.
also i have tried to create a new project and implement the same functionality and its working fine.

https://www.screencast.com/t/zGwvf1IiWC

Please help.

Xamarin Forms Line Chart

$
0
0

Hi All,

I am used xamarin.forms(PCL) and I want to do Line chart in Android and iOS

Can any one please suggest me which library is best for xamarin.forms.

Your help is relay appreciated for me.


ScrollView with a Label cut bottom text on Android Vertical mode

$
0
0

Hi
I need to show the user an long eula text.
I have an Label in a ScrollView i a Grid.

This code works on iOS and on Android in landscape mode?!?!?
but in Vertical mode on android it cut the text off about when there is about 20% left.

Does anybody have an idea what is going on?

(the "HeaderView" is just a gridview that i use to display a header)

`

public eulaAcceptPage(string eula)
{
    this.eula = eula;
    InitializeComponent();
    setlayout();
}

private void InitializeComponent()
{
    header = new HeaderView( text.consent(), text.back(), false);
    buttomHeader = new HeaderView(text.no(), text.giveConsent(), text.yes());

    consentText = new Label {
        Text = eula,
        LineBreakMode = LineBreakMode.WordWrap,
    };

    scrolltextView = new ScrollView {
        Orientation = ScrollOrientation.Vertical,
        Content = consentText,
    };

}

private void setlayout()
{
    Padding = new Thickness(1, Device.OnPlatform(20, 0, 0), 1, 5);

    grid = new Grid
    {
        VerticalOptions = LayoutOptions.FillAndExpand,
        HorizontalOptions = LayoutOptions.FillAndExpand,
        RowDefinitions =
        {
            new RowDefinition { Height = new GridLength(60, GridUnitType.Absolute) },   //0
            new RowDefinition { Height = GridLength.Auto },                             //1
            new RowDefinition { Height = new GridLength(60, GridUnitType.Absolute) },   //2
        },
        ColumnDefinitions =
        {
            new ColumnDefinition { Width = GridLength.Star }, //0
            new ColumnDefinition { Width = GridLength.Auto }, //1
            new ColumnDefinition { Width = GridLength.Star }, //2
        }
    };

    grid.Children.Add(scrolltextView, 0, 3, 1, 2);

    grid.Children.Add(header, 0, 3, 0, 1);
    grid.Children.Add(buttomHeader, 0, 3, 2, 3);

    Content = grid;
}

protected override void OnDisappearing()
{
    header.leftButton.Clicked -= backButton_Clicked;
    buttomHeader.rightButton.Clicked -= ConsentGivenButton_Clicked;
    base.OnDisappearing();
}

protected override void OnAppearing()
{
    header.leftButton.Clicked += backButton_Clicked;
    buttomHeader.rightButton.Clicked += ConsentGivenButton_Clicked;
    base.OnAppearing();
}

`

android listview crashes not on iOS or UWP

$
0
0

This code works fine on iOS and UWP however on android it crashes. If I comment out hte mainStack.Children.Add(listView) line all works ok.

From output window
10-14 19:53:33.768 D/Mono ( 2550): Found as 'java_interop_jnienv_call_void_method'.
10-14 19:53:33.772 D/Mono ( 2550): Assembly Ref addref Xamarin.Forms.Platform.Android[0xa3ad5f80] -> Xamarin.Android.Support.v7.AppCompat[0xa3ad5b60]: 2
Unhandled Exception:

System.NullReferenceException: Object reference not set to an instance of an object.

10-14 19:53:40.964 D/Mono ( 2550): [0x8f47f920] worker finishing
Thread finished: #3
The thread 'Unknown' (0x3) has exited with code 0 (0x0).

From call stack
0x118 in Xamarin.Forms.Platform.Android.VisualElementRenderer<Xamarin.Forms.View>.SetElement at C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:193,5 C#
0x2E in Xamarin.Forms.Platform.Android.VisualElementRenderer<Xamarin.Forms.View>.Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement at C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:126,4 C#
0x21 in Xamarin.Forms.Platform.Android.Platform.CreateRenderer at C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\Platform.cs:289,4 C#
0xFC in Xamarin.Forms.Platform.Android.VisualElementRenderer<Syncfusion.SfNavigationDrawer.XForms.SfNavigationDrawer>.SetElement at C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:190,4 C#
0x2E in Xamarin.Forms.Platform.Android.VisualElementRenderer<Syncfusion.SfNavigationDrawer.XForms.SfNavigationDrawer>.Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement at C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:126,4 C#
0x21 in Xamarin.Forms.Platform.Android.Platform.CreateRenderer at C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\Platform.cs:289,4 C#

public View getDrawerContent()
{
StackLayout mainStack = new StackLayout();
mainStack.Opacity = 1;
mainStack.Orientation = StackOrientation.Vertical;
mainStack.HeightRequest = 500;
mainStack.BackgroundColor = Color.White;

        /*ObservableCollection<String> list = new ObservableCollection<string>();
        list.Add("Home");
        list.Add("Health Data");
        list.Add("Doctors");
        list.Add("Symptoms");
        */

        ListView listView = new ListView();

        listView.WidthRequest = 50;
        listView.VerticalOptions = LayoutOptions.FillAndExpand;
        listView.ItemsSource = new string[]{

"Home",
"Health Data",
"Doctors",
"Symptoms"

};

        listView.ItemSelected += ListView_ItemSelected;
        mainStack.Children.Add(listView);
        return mainStack;
    }

The "XamlCTask" task failed unexpectedly.

$
0
0

Hello Team,
I am facing this The "XamlCTask" task failed unexpectedly. problem after adding the xamarin.forms.maps package to my application.

Waiting for your response.

MVVM issue

$
0
0

I have a weird issue with mvvm and custom controls. Here is some code!

MainPage.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:local="clr-namespace:TestXamForms"
                 x:Class="TestXamForms.MainPage">

        <local:TestControl Detail="{Binding Detail, Mode=TwoWay}"/>

    </ContentPage>

MainPage.xaml.cs

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }

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

        BindingContext = new MainPageVM();
    }
}

public class MainPageVM : ObservableObject
{
    public DetailModel Detail { get; set; } = new DetailModel { Name = "fish" };
}

TestControl.xaml

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="TestXamForms.TestControl">
    <ContentView.Content>
        <Label Text="{Binding Detail.Name}"/>
    </ContentView.Content>


TestControl,xaml.cs

public partial class TestControl : ContentView
{
public static readonly BindableProperty DetailProperty =
BindableProperty.Create("Detail", typeof(DetailModel), typeof(TestControl), propertyChanged: DetailPropertyChanged);

    private static void DetailPropertyChanged(BindableObject bindable, object oldValue, object newValue)
    {
        (bindable as TestControl).VM.Detail = newValue as DetailModel;
    }

    public DetailModel Detail
    {
        get => (DetailModel)GetValue(DetailProperty);
        set => SetValue(DetailProperty, value);
    }

    private TestControlVM VM
    {
        get => BindingContext as TestControlVM;
        set => BindingContext = value;
    }

    public TestControl()
    {
        InitializeComponent();
        VM = new TestControlVM();
    }
}

public class TestControlVM : ObservableObject
{
    private DetailModel _detail;

    public DetailModel Detail
    {
        get => _detail;
        set => SetProperty(ref _detail, value);
    }
}

The issue is that Detail in TestControl is not getting set, ie DetailPropertyChanged doesnt fire nor does the setter for Detail in TestControl.xaml.cs.

Have I missed something massively obviously in my bindings? It seems to be that when the BindingContext in MainPage.xaml.cs is changed in the OnAppearing method, it doesnt propagate this change down through the bindings. If this is the case (and expected behaviour), how can I overcome this? I'm hoping someone can help!

how to upload file in userinterface?

Viewing all 76418 articles
Browse latest View live


Latest Images

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