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

Accessing controls on the Shared project from the platform projects

$
0
0

Hi.
I'm new to Xamarin.Forms and I need a bit of guidance.

What I'm trying to do :

  • Feed the device's calendar data (events, appointments, etc.) to the Third Party Calendar Xamarin.Forms control

Control is located in the shared project.

From what I understand there is no way to access calendar from Xamarin.Forms shared project?
It seems that I will have to write platform specific code for iOS and Android to get the Calendar data.

How can I feed this data back to my third party calendar view control, from Android and iOS?

My best guess at the moment is that I can follow documentation on Calendar for Xamarin.Android and Xamarin.iOS, and use this code to get the data on both platforms. But I'm not sure how can I feed this data back to my control residing in the shared project.

Any kind of guidance is welcome. Thanks!


Different background for each selection in a list

$
0
0

Hello,

I am creating a list. I need each item in the list to have a different background color. With the code I'm using the background color is white. I'm not sure what I'm doing wrong.

using Xamarin.Forms;
namespace App5
{
public partial class MainPage : ContentPage
{
public class ListItem
{
public string Title { get; set; }
public Color ForeColor { get; set; }
public Color BackgroundColor { get; set; }
}
public MainPage()
{
InitializeComponent();

        var listView = new ListView();
        listView.ItemsSource = new ListItem[] {

        new ListItem {Title ="Red", ForeColor = Color.White, BackgroundColor = Color.Red},
        new ListItem {Title ="Orange", ForeColor = Color.White, BackgroundColor = Color.Orange},
        new ListItem {Title ="Yellow", ForeColor = Color.White, BackgroundColor = Color.Yellow},
        new ListItem {Title ="Green", ForeColor = Color.White, BackgroundColor = Color.Green},
        new ListItem {Title ="Blue", ForeColor = Color.White, BackgroundColor = Color.Blue},
        new ListItem {Title ="Violet", ForeColor = Color.White, BackgroundColor = Color.Violet}
        };


        listView.RowHeight = 80;
        listView.ItemTemplate = new DataTemplate(typeof(ListItemCell));
        Content = listView;

        listView.ItemTapped += async (sender, e) => {
            ListItem item = (ListItem)e.Item;
            await DisplayAlert("Tapped", item.Title.ToString() + " was selected.", "Ok");
            ((ListView)sender).SelectedItem = null;
        };
    }
    class ListItemCell : ViewCell
    {
        public ListItemCell()
        {
            Label titleLabel = new Label
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                FontSize = 25,
                FontAttributes = Xamarin.Forms.FontAttributes.Bold,
                TextColor = Color.White
            };
            titleLabel.SetBinding(Label.TextProperty, "Title");

            StackLayout viewLayoutItem = new StackLayout()
            {
                HorizontalOptions = LayoutOptions.StartAndExpand,
                Orientation = StackOrientation.Vertical,
                Children = { titleLabel}
            };

            StackLayout viewLayout = new StackLayout()
            {
                HorizontalOptions = LayoutOptions.StartAndExpand,
                Orientation = StackOrientation.Horizontal,
                Padding = new Thickness(25, 10, 55, 15),
                Children = { viewLayoutItem }
            };
            View = viewLayout;
        }
    }
}

}

DateTime data type and retrieving records in SQLite

$
0
0

I am having a problem pulling records from my Sqlite db by date.
Here is my model:

public class exerciseTbl
{
[PrimaryKey]
public int exerciseID { get; set; }
public string exerciseName { get; set; }
public DateTime exerciseDate { get; set; }
}

Most of the records just use date.today when inserting. When I insert records, it looks like: 2019-04-09T00:00:00.000. When I try to do a query using date.today, I don't get any records. I have read that I should store datetimes as strings (I am not using ticks) but the model would not correctly represent the data and would make migration to a different database platform a pain. There are many examples but all of them use actual strings instead of date.today or date.now. If anyone can offer any advice on how to accomplish this I would appreciate it.
Thank you,
Rob

Resize ListView ViewCell after binding

$
0
0

I would like to be able to resize (the height) of a viewcell after it has been bound to the underlying data item. Currently, content is being clipped because it exceeds the default height of the viewcell.

Get BackPressButton Event

$
0
0

Hi All,

How to I know user have pressed back button from physical back button or application top Back Icon?

Need to Modifify the navigation method in order to have more navigation than one

$
0
0

My navigation method in the base abstract class

          public abstract void Navigate(SelectedItemChangedEventArgs e); '

In one of my View classes, I need to have more than one navigation when some button clicked or tapped. using my navigate function only I can use for one navigation I need to improve the navigate method to have improved so it can use for multiple navigations. I am a little clueless here what should I do do a relay command or use generic. what I need to change in order to use this method for multiple navigation purposes

  private void JournalSelected(object sender, SelectedItemChangedEventArgs e)
 {
    if (e?.SelectedItem == null) return;
    JournalGroupList.SelectedItem = null;
    Navigate(e);
 }

public override async void Navigate(SelectedItemChangedEventArgs e)
{
    JournalHistoryViewPage journalHistoryViewPage = App.Container.Resolve<JournalHistoryViewPage>();
    journalHistoryViewPage.BaseViewModel.JournalGroup = e.SelectedItem as JournalGroup;
    journalHistoryViewPage.BaseViewModel.SelectedPatient = BaseViewModel.SelectedPatient;
    await Navigation.PushAsync(journalHistoryViewPage, true);
}

 private async void VitalSigns_Tapped(object sender, System.EventArgs e)
 {
    var vitalSignsViewPage = App.Container.Resolve<VitalSignsViewPage>();
    vitalSignsViewPage.BaseViewModel.SelectedPatient = BaseViewModel.SelectedPatient;
    await Navigation.PushAsync(vitalSignsViewPage, true);
}

As I used Navigate Function in journalselected I also need it to use for VitalSigns_tapped. In here I feel like I have duplicated the code and did not use the method properly

Xamarin Forms Picker Problem!

$
0
0

I have a problem with my Pickers!
If i open a picker in the Android App, but then tap anywhere outside so that it closes, the Picker is not responding anymore, and there is no ability to select it again.

Seems to only happen to the regular pickers! Date and Time Pickers are working fine.

Please Help.

Create a menu with sub menus in one option using MasterDetailPage

$
0
0

Hello,

I'm doing a menu using master detail page. And I need to add submenus only in one of the options.
I have looked at grouping in listviews, but that would work if every option have sub menus.

What would be the best way to do this?

Thanks


Android.Views.View to my own class

$
0
0

Hi! I've been using a nuget package called MultiGestureView to get the long tap event on a viewcell but the event give me a Android.Views.View on the sender and dont know how to get the data from that. The binding context of the listview is a List of MyClass (for example)

XAML:

<ListView>
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <gesture:MultiGestureView LongPressed="Gesturev_LongPressed">

                        <Grid BackgroundColor="{Binding colorPrior}" TranslationX="{Binding PosX}">
                <!-- some data with bindings-->
                        </Grid>
                    </gesture:MultiGestureView>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

CS:

private void Gesturev_LongPressed(object sender, EventArgs e)
    {
        MyClass myClass = sender as MyClass;
    //I tried everything here
        if (!longTap)
        {
            longTap = true;
            Task tempo = TempLongTap(360);
            DisplayAlert("Long Pressed", myClass.name, "Ok");
        }
    }

Linespacing for multiline/wrapped text

$
0
0

Hello,

i am currently trying to develop a app for iOS and android with Xamarin.Forms and encountered a problem:
I got a label, filled with text, that gets wrapped over two or three lines. The text gets highlighted with spans.
Now i want to have a spacing between these lines but dont know how. I found the LineHeight property but it doesnt seem like theres a spacing.

Is there a good way to make this work?

Greetings
Korblie

VS 2017/2019 Xamarin.Forms creating button event handler naming problem (Mac)

$
0
0

Hello, I am having an issue with creating a button event handler, it always creates an event handler with the name Handle_Clicked. If there are more event handlers then it just adds a number to Handle_Clicked. There is no other option to choose when creating an event handler other than Handle_Clicked.
Thanks.
Edit: Noticed I posted in the wrong section but I don't know how to delete the post.

ADMob not show in Android - Xamarin forms

$
0
0

Good Morning,

I Have a solution app in xamarin forms, and I need add ADMOB, and I do this, but, my ad not show, please help me:

My AdMob work:

I use plugin: Xamarin.GooglePlayServices.Ads - Version: 60.1142.1 - the last version.

MainActivity onCreate, My row of initialize MobileAd:
MobileAds.Initialize(ApplicationContext, "ca-app-pub-xxxxxxxxxxxxxxxxx~xxxxxxxxxx"); I tryed with ID: "xxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxx", but I not have success

My ADMobView class:

 **public class AdMobView : View
 {
 }**

My AdMobRenderer:

    ** [assembly: ExportRenderer(typeof(AdMobView), typeof(AdMobViewRenderer))]
     namespace Anuncie.Droid.Renderes
     {
         public class AdMobViewRenderer : ViewRenderer<AdMobView, AdView>
         {
             public AdMobViewRenderer(Context context) : base(context) { }

             string adUnitId = string.Empty;
             //Note you may want to adjust this, see further down.
             AdSize adSize = AdSize.SmartBanner;
             AdView adView;
             AdView CreateNativeAdControl()
             {
                 if (adView != null)
                     return adView;

                 // This is a string in the Resources/values/strings.xml that I added or you can modify it here. This comes from admob and contains a / in it
                 adUnitId = "xxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxx"; I tryed with ca-app-pub-xxxxxxxxxxxxxxxxx~xxxxxxxxxx, but I not have success
                 adView = new AdView(Forms.Context);
                 adView.AdSize = adSize;
                 adView.AdUnitId = adUnitId;

                 var adParams = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent);

                 adView.LayoutParameters = adParams;

                 adView.LoadAd(new AdRequest
                                 .Builder()
                                 .Build());
                 return adView;
             }

             protected override void OnElementChanged(ElementChangedEventArgs<AdMobView> e)
             {
                 base.OnElementChanged(e);
                 if (Control == null)
                 {
                     if (Control == null)
                     {
                         CreateNativeAdControl();
                         SetNativeControl(adView);
                     }
                 }
             }
         }
     }**

Thanks

Forms 4 CarouselView

$
0
0

Hi there,

I am trying to create something akin to the tabbed page but within an existing page, the current plan is to use the Forms 4 Carousel View and make changes to another control to indicate the current view.

I realise this is pre-release however I cannot seem to find a current position or selected item property to bind to in the Carousel View in order to link the two controls, does anyone know if this is possible? Other comments have suggested using a NuGet package implementation of the Carousel View.

Thanks in advance,

Niall

How can I change a navbar color of single page?

$
0
0

I have to change color of only one navbar in my App.
Until now I handle color of my navbars in this way:

BarBackgroundColor = Color. Blue;
in this case I can't.

Before i did:

Detail= new NavigationBar(new Page)
{
BarBackgroundColor = Color. Blue
}

Now my page is not a Detail of a MasterPage. Is just a content page linked to a Detail.
In the first page i have a method:

async void Handle_EditProfile(object sender, Event Args e){

  await Navigation.PushAsync(new EditProfile());

 // I wanna set here color of my navbar ( I wanna change color navbar only for EditProfile Page)

}

Admob Rewarded Video support for Xamarin

$
0
0

Hi!

I've been struggling for some time to implement rewarded video ads in my app, using Admob network. I've managed to display a video ad on android, but I simply can't have the listener to trigger the OnRewarded event. This is how I implement it:

`

public class AdMobInter : IAdmobInter
{
    InterstitialAd _ad;

    public void Show(string adUnit)
    {
        var context = Android.App.Application.Context;
        _ad = new InterstitialAd(context);
        _ad.AdUnitId = adUnit;

        var intlistener = new InterstitialAdListener(_ad);
        intlistener.OnAdLoaded();
        _ad.AdListener = intlistener;

        var requestbuilder = new AdRequest.Builder();

        _ad.LoadAd(requestbuilder.Build());
    }
}

public class InterstitialAdListener : AdListener, IRewardedVideoAdListener
{
    readonly InterstitialAd _ad;

    public InterstitialAdListener(InterstitialAd ad)
    {
        _ad = ad;
        _ad.RewardedVideoAdLoaded += (o, e) => OnRewardedVideoAdLoaded();
        _ad.RewardedVideoAdClosed += (o, e) => OnRewardedVideoAdClosed();
    }

    public override void OnAdLoaded()
    {
        base.OnAdLoaded();

        if (_ad.IsLoaded)
        {
            _ad.Show();
    //THIS EVENT WORKS//
            //MY CODE HERE//

        }
    }

    public override void OnAdFailedToLoad(int errorCode)
    {
        base.OnAdFailedToLoad(errorCode);
//THIS EVENT WORKS//
        //MY CODE HERE//
    }

    public void OnRewarded(IRewardItem reward)
    {
     //THIS EVENT WON'T TRIGGER//
    //MY CODE HERE//
    }

    public void OnRewardedVideoAdClosed()
    {
        //THIS EVENT WORKS//
    //MY CODE HERE//
    }

    public void OnRewardedVideoAdFailedToLoad(int errorCode)
    {

    }

    public void OnRewardedVideoAdLeftApplication()
    {

    }

    public void OnRewardedVideoAdLoaded()
    {
        //THIS EVENT WORKS//
    //MY CODE HERE//
    }

    public void OnRewardedVideoAdOpened()
    {

    }

    public void OnRewardedVideoStarted()
    {

    }
}

`

I've read in some places that the Admob network only support native frameworks, and Xamarin is still not supported. Is this really the case? I'm thinking in just leaving it like that and the user will get an internal reward regardless of watching the whole video or not. It's not ideal for me, but what can I do? I'm using a PCL project, currently working on the Android.

How do you guys deal with that in your apps? Any hint is appreciated!


Getting Started with Xamarin.Forms

$
0
0

Hi Guys,

I am new to Xamarin.Forms and would like to ask for guidance in getting started with an app (from development, to hosting, DB interactions etc)
I have Xamarin installed and I am able to get a really basic APP going, I would like to get more guidance on the hosting and DB interaction aspects.

I'd appreciate any form of resources that may assist me in this regard.

Regards

How to access Samba Share folder files in local network?

$
0
0

Hi all,

I would like to access Samba Share folder files in local network using Xamarin mobile app, with following functions:

To detect all existing files

To delete specific file

To add specific file

I could access this Samba Share folder files using Windows PC. But no clue how to achieve this via Xamarin.

Could anyone assist on this?

Thanks.

Any library to encode and decode images in JPEG 2000 format?

$
0
0

I'm looking for a library to encode and decode images in JPEG 2000 format. I was testing CSJ2K but I didn't have too much success.

Any ideas?

Thanks in advance!

Xamarin Forms Map becomes unresponsive if used in new shell

$
0
0

Hello,

Does anyone has this problem that when a page with forms map is used as menu item in new shell navigation, the map becomes quite unresponsive to drag events.

Bindable Property on Custom Control Error

$
0
0

Hi,

I have a custom control for entry, and Binding for the text is not working. It works before this, and now it's not working anymore. I have no idea why it stopped working.

EntryBinding.xaml

<?xml version="1.0" encoding="UTF-8"?>
<Grid xmlns="http://xamarin.com/schemas/2014/forms"
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
      x:Class="TestingApp.EntryBinding">
    <Entry Text="{Binding Path=MyText, Mode=TwoWay}"/>
</Grid>

In my EntryBinding I have a BindableProperty called MyText

public static readonly BindableProperty MyTextProperty = BindableProperty.Create(
    "MyText",
    typeof(string),
    typeof(EntryBinding),
    "",
    propertyChanged: OnMyTextChanged);

private static void OnMyTextChanged(BindableObject obj, object oldValue, object newValue)
{
    var item = obj as EntryBinding;
    var newV = (string)newValue;
    var oldV = (string)oldValue;
}

public string MyText
{
    get
    {
        return (string)GetValue(MyTextProperty);
    }
    set
    {
        SetValue(MyTextProperty, value);
    }
}

Then I tried to use the custom control in my MainPage like this:
<local:EntryBinding MyText="{Binding TheText}"/>

However, when I run, I receive this error: Binding: 'TheText' property not found on 'TestingApp.MainPage', target property: 'TestingApp.MYCB.MyText'

Below is my MainPage and my Items class

public partial class MainPage : ContentPage
{
    Items items = new Items();

    public MainPage()
    {
        InitializeComponent();

        BindingContext = items;
    }

    void Handle_Clicked_2(object sender, System.EventArgs e)
    {
        items.TheText = "WOW";
    }
}

public class Items : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    string _TheText = "";
    public string TheText
    {
        get { return _TheText; }
        set
        {
            _TheText = value;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("TheText"));
        }
    }
}

I don't know where went wrong. It run perfectly before this, and now it just have the error I mentioned above.

Thanks in advance,
AziziAziz

Viewing all 76418 articles
Browse latest View live


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