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

Can't see CarouselPage template in the list of templates

$
0
0

I am going to create the app with carousel page, but there is no appropriate template in the list.
There is no tab "Cross-platform" in Visual C# only "Xamarin.Forms"
I can see:
-View.xaml
-View.cs
-MasterDetailPage.xaml
-ListViewPage.xaml
-TabbedPage.xaml
-ContentPage.xaml
-ContentPage.cs
-ViewCell.xaml

Note. If I try to create new content page and change in xaml "ContentPage" to "CarouselPage" or change existing MainPage's xaml it doesn't work at all. It doesn't want to inherit CarouselPage.

P.S. I created shared project, blankapp


How to show text on UWP toolbar instead of using an icon?

$
0
0

The Xamarin ToolbarItem has a property Text and Icon, but I want to show text on the toolbar instead of an image. Is this possible without creating an image with text on it? I tried using a custom renderer but I see no way to achieve this.

Currently it looks like this:

But I want it to be like this:

How can I achieve this in UWP?

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?

Create custom entry for OTP.

$
0
0

How can we create custom entry to fill the OTP automatically.
like this, please see the attachment.

How to calculate viewcell height?

$
0
0

Can calculate viewcell height? Sorry, my bad english.

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

Custom MultiPage?

$
0
0

Hi,

Has anyone tried to use MultiPage directly? I tried to use it like this, and everything works except for the backbutton in the NavigationPage on iOS.

Is there anything more I need to override? When I put a NavigationPage in a TabbedPage it works fine.

public class MyMultiPage : MultiPage<Page>
    {
        public MyMultiPage() : base()
        {
            var children = new List<Page>() {
                new MenuPage(),
                new NavigationPage(new MainPage())
            };
            this.ItemsSource = children;
            this.CurrentPage = children[1];
            this.CurrentPage.TranslationX = 50; // Move the main page 50 points to the right
        }
        override protected Page CreateDefault(object item)
        {
            return (Page)item;
        }
    }

How to update listview when property of item changed?

$
0
0

Is there a way to do it? Sorry, my bad english.


How to make in-app purchasing in cross platform application?

$
0
0

Hello All,

I am trying to implement InApp purchasing from iOS & Android app.

I followed this link. But not getting success.

Please comment your code/ideas.

Xamarin Android crashing after loading splash_screen

$
0
0

I dont know why has been crashing , can i help you resolve issue? thanks

using Android.App;
using Android.Content.PM;
using Android.Views;
using Android.OS;
using Android.Util;
using FormApp.Helpers;
using Acr.UserDialogs;
using FFImageLoading.Transformations;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
using AToolbar = Android.Support.V7.Widget.Toolbar;

namespace FormApp.Droid
{
[Activity(Label = "FormApp.Droid",
Icon = "@drawable/icon",
MainLauncher = true,
Theme = "@style/MainTheme",
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
NoHistory = true
)
]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
private static MainActivity _this;
public static AToolbar ToolBar { get; private set; }

    public static View RootFindViewById<T>(int id) where T : View
    {
        return _this.FindViewById<T>(id);
    }
    public MainActivity()
    {
        _this = this;
        Android.Support.V7.App.AppCompatDelegate.CompatVectorFromResourcesEnabled = true;
    }

    protected override void OnCreate(Bundle bundle)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;
        base.OnCreate(bundle);

        Rg.Plugins.Popup.Popup.Init(this, bundle);
        Xamarin.Forms.Forms.Init(this, bundle);
        UserDialogs.Init(this);
        FFImageLoading.Forms.Platform.CachedImageRenderer.Init(true);          
        var ignore = new CircleTransformation();

        RequestedOrientation = Xamarin.Forms.Device.Idiom == Xamarin.Forms.TargetIdiom.Phone ? ScreenOrientation.SensorPortrait : ScreenOrientation.SensorLandscape;
        MakeStatusBarTranslucent(true);
        LoadApplication(new App());
        Xamarin.Forms.Application.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);

    }

    public override bool OnCreateOptionsMenu(IMenu menu)
    {
        ToolBar = FindViewById<AToolbar>(Resource.Id.toolbar);
        return base.OnCreateOptionsMenu(menu);
    }


    public void OnTranslucentStatusRequest(StatusBarHelper helper, bool makeTranslucent)
    {
        MakeStatusBarTranslucent(makeTranslucent);
    }

    private void MakeStatusBarTranslucent(bool makeTranslucent)
    {
        if (makeTranslucent)
        {
            SetStatusBarColor(Android.Graphics.Color.Transparent);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                Window.DecorView.SystemUiVisibility = (StatusBarVisibility)(SystemUiFlags.LayoutFullscreen | SystemUiFlags.LayoutStable);
            }
            else
            {
                using (var value = new TypedValue())
                {
                    if (Theme.ResolveAttribute(Resource.Attribute.colorPrimaryDark, value, true))
                    {
                        var color = new Android.Graphics.Color(value.Data);
                        SetStatusBarColor(color);
                    }
                }

                if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                {
                    Window.DecorView.SystemUiVisibility = StatusBarVisibility.Visible;
                }
            }
        }
    }
}

}

Maintain hamburger menu and back button in MasterDetailPage

$
0
0

I have a requirement from our UI team to maintain the hamburger menu when a user navigates with a Detail page. I have seen this is successfully done in a few apps, namely the Amazon app.

Has anyone done this before? I would presume a custom renderer would be required?

TimePicker - using string array instead of default digits ... is it possible?

$
0
0

I was looking for a drop down type control to use in Xamarin Forms. I found the picker - which works, but isn't quite what I was hoping for. I also found the TimePicker which from a visual standpoint, is exactly what I want. So, is there a way to set what fills each part of the TimePicker ... like an array of strings instead of digits 1 through 12?

If not, is there anything out there that provides a similar look and function?

Xamarin TabbedPage Performance On Children.Add

$
0
0

Good Afternoon,
I have a question regarding the performance of the tabbed page and whether there is a more efficient way to load the tabs into the page, without any frame loss or process hang.
Regarding this issue, I have been having a few issues with TabbedPage in Xamarin.Forms. My project currently consists of a Listview with 104 components. When I click on one of the items it opens up a tabbed page consisting of 3 tabed pages. I start the tabbed page using the following code

int Clicked = 0;
public async Task CheckClick(Page data)
{
            Clicked += 1;
            if (Clicked == 1)
            {
                await Navigation.PushAsync(data);
                List_View.SelectedItem = null;
            }
}
public async void OnSelection(object sender, SelectedItemChangedEventArgs e)
{

            if (e.SelectedItem == null)
            {
                return;
            }
            var Cell = e.SelectedItem as DataSource;
            switch (Cell.ID)
            {
                case 0:
                    await CheckClick(new Function_One());
                    break;
        }
}

The real problem comes after, whether I pre load the information ahead of time or do what ever, whenever I call Children.Add(data); the whole application hangs for 1 or 2 seconds and than allows the page to load. The code is as follows.

public class Function_One : TabbedPage
{
    private async Task Test()
    {
                //
                var data = new NewPageData("", "", "OP.png", "Persian.png", Description, Usage, Storage, Data);
                var data2 = new NewMedicalPage(Medical_Info, Translation, startinfo);
                var data3 = new NewNotePage("", 0);

                data.Icon = "Spice_Info.png";

                await Task.Delay(100);// Little await to load the page first before hang

                Device.BeginInvokeOnMainThread(async () =>
                {
                    Children.Add(data);// HERE is the freeze
                    Children.Add(data2);// these
                    Children.Add(data3);// 3 (Adding of the Tabs)
                });
    }
    public void UpdateData()
    {
                Task.Run(async () =>
                {
                    try
                    {
                        Description.Spans.Add(new Span
                        {
                            Text = "Data.... ",
                            FontSize = 18,
                            FontFamily = variables.fontFamily
                        });


                        Usage.Spans.Add(new Span
                        {
                            Text = "MoreData...",
                            FontSize = 18,
                            FontFamily = variables.fontFamily
                        });

                        Storage.Spans.Add(new Span
                    {
                        Text = "LastData...",
                        FontSize = 18,
                        FontFamily = variables.fontFamily
                    });

                    await Test();
                }
                catch { }
            }).ConfigureAwait(false);

    }
    public Function_One()
    {
            UpdateData();
                BarBackgroundColor = MainColor;
                BarTextColor = Color.WhiteSmoke;
                Title = "Page";
    }
}

NOTE: (This Project Is Completely An Offline Project, No Internet Needed)

If anyone could explain to me a better method for loading the data while keeping the application flowing and smooth, they would be appreciated. The data does not have to load all at once, just as long as the page opens as soon as its clicked!

ListView with a Picker in a cell works in UWP, iOS but not Droid. Any insights?

$
0
0

Below is a link to a sample program using Visual Studio 2017 v15.8.2 and Xamarin Forms v3.1.
The app displays one page that has a ListView with a custom cell that displays a couple of text fields
and a Picker. The Picker does not show the selected values in Android. It works as expected in UWP
(pre-populated picker value is displayed and selected picker values are also displayed)

[Edit] When The Droid page loads, the debug statements indicate that the SelectedIndex in each Cell has the right value and then, after OnAppearing the SelectedIndex(s) get changed to -1 so the Pickers show blank. Also, when a Picker has a value selected, it displays briefly and then gets replaced by a blank.
[/Edit]

The data required by the Listview is hard coded. To run this, all you need is to download it,
open it in the correct version of Visual Studio with Xamarin Forms and run it in either Android or UWP.
(Note: I have not tested this version in iOS, however in my original that is part of my active
development, the iOS version works as expected)

https://bitbucket.org/WillAutio/filelist/src/master/

And here are the relevant snippets of code. From the XAML:
`

        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <ViewCell.View>
                        <StackLayout Orientation="Vertical" Margin="0,0,0,15" BackgroundColor="Green">

                            <StackLayout Orientation="Horizontal">
                                <Label Text="{Binding reportID}" FontSize="18"  BackgroundColor="White" TextColor="Black"
                                           MinimumWidthRequest="40"/>
                                <Label Text="{Binding question}" FontSize="18"  BackgroundColor="White" TextColor="Black"/>
                            </StackLayout>

                            <StackLayout Orientation="Horizontal">

                                <Picker x:Name="AnsPicker"  
                                    TextColor="Black" BackgroundColor="Yellow" ItemsSource="{Binding AnswerList}"
                                    HeightRequest="50" WidthRequest="150"
                                    SelectedIndex="{Binding Selected, Mode=TwoWay}"                                    
                                    SelectedIndexChanged="OnAnswerPicker_Changed" />


                            </StackLayout>

                            <StackLayout Orientation="Vertical" Margin="0,0,0,0"  BackgroundColor="Black" >
                                <Entry x:Name="Explanation"   Text="{Binding explanation , Mode=TwoWay}" 
                                           FontSize="18"  BackgroundColor="White" 
                                           TextColor="Black" Placeholder="Explanation" Margin="0,1,0,5" 
                                           MinimumWidthRequest="200"  TextChanged="Entry_TextChanged" />
                            </StackLayout>

                        </StackLayout>
                    </ViewCell.View>

                </ViewCell>

            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>`

From the code behind:

`
public partial class MainPage : ContentPage
{
MainPageViewModel MPVM { get; set; }
public MainPage()
{

        InitializeComponent();

        MPVM = new MainPageViewModel();

        this.BindingContext = MPVM;
        MyLV.ItemsSource = MPVM.MPM.ocMC;

    }

    protected override void OnAppearing()
    {
        base.OnAppearing();
    }
    private void Entry_TextChanged(object sender, TextChangedEventArgs e)
    {
        // doesn't matter what goes in here

    }
    private void OnAnswerPicker_Changed(object sender, ToggledEventArgs e)
    {
        Picker picker = sender as Picker;
        MyClass item = (MyClass)((Picker)sender).BindingContext;
        Debug.WriteLine("\n                             item " + item.ToString());
        Debug.WriteLine("\n MTVM.MTM.ocMC[item.reportID - 1] " + MPVM.MPM.ocMC[item.reportID - 1].ToString());


        MPVM.MPM.ocMC[item.reportID - 1].yesno = item.yesno;
        MPVM.MPM.ocMC[item.reportID - 1].Selected = item.Selected;
        Debug.WriteLine("\n MTVM.MTM.ocMC[item.reportID - 1] " + MPVM.MPM.ocMC[item.reportID - 1].ToString());

        Debug.WriteLine("\n ");

    }

}

`

And MyClass:
`
public class MyClass : ObservableObject
{
public int? myKey { get; set; } // local primary key

    public int reportID { get; set; } // 

    public bool? _yesno;
    public bool? yesno    // null => None; true => Yes; false => No;
    {
        get
        {
            return this._yesno;
        }
        set
        {
            if (_yesno != value)
            {
                _yesno = value;

                OnPropertyChanged("yesno");
            }
        }

    }
    //public string explanation { get; set; }
    private string _explanation;
    public string explanation
    {
        get
        {
            return this._explanation;
        }
        set
        {
            if (_explanation != value)
            {
                if (_explanation == null && value == "")
                {  //  _explanation starts out as a null. The constructor sets it to "". 
                   //  That triggers a change that we do not care about.
                    _explanation = value;
                }
                else
                {
                    _explanation = value;
                    toupload = 1; // on change to explanation mark this record for upload
                    OnPropertyChanged("explanation");
                }
            }
        }
    }
    //public string prjnum { get; set; }

    public long projectID { get; set; }
    public int toupload { get; set; }    // 1 means the record needs to be uploaded

    public bool ShowToggle { get; set; }

    private bool _answerToggle;
    public bool AnswerToggle
    {
        get
        {
            return this._answerToggle;
        }
        set
        {
            if (_answerToggle != value)
            {
                _answerToggle = value;
                toupload = 1; // on change to AnswerToggle mark this record for upload
                OnPropertyChanged("AnswerToggle");
            }
        }

    }

    public ObservableCollection<string> AnswerList { get; set; }

    public int _selected;
    public int Selected
    {
        get
        {
            return this._selected;
        }
        set
        {
            if (_selected != value)
            {
                _selected = value;
                toupload = 1; // on change to AnswerToggle mark this record for upload
                if (_selected == 0)
                {
                    yesno = null;
                }
                else if (_selected == 1)
                {
                    yesno = true;
                }
                else if (_selected == 2)
                {
                    yesno = false;
                }

                OnPropertyChanged("Selected");
            }
        }

    }

    public string question { get; set; }

    public MyClass()
    {
        AnswerList = new ObservableCollection<string>();
        AnswerList.Add("None");
        AnswerList.Add("Yes");
        AnswerList.Add("No");
    }

    public override string ToString()
    {
        string ans = 
                     " yesno  =" + yesno +
                     " Selected  =" + Selected +
                     " myKey  =" + myKey +
                     " reportID  =" + reportID +
                     " toupload  =" + toupload +
                     " projectID  =" + projectID +
                     " question  =" + question;
        return ans;
    }
}

`

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?


How to pass URL from PCL to Renderer class?

$
0
0

I want to re-use my webview renderer class. How to pass in the URL to the renderer class from the PCL?

Code Snippett:

public class CustomWebViewRenderer : ViewRenderer<CustomWebView, WKWebView>
{
    protected override void OnElementChanged(ElementChangedEventArgs<CustomWebView> e)
    {
        base.OnElementChanged(e);

        if (Control == null)
        {
            var config = new WKWebViewConfiguration { };
            var webView = new WKWebView(Frame, config)
            {
                NavigationDelegate = new CustomWKNavigationDelegate()
            };

            SetNativeControl(webView);
        }

        if (e.NewElement != null)
        {
            NSUrlRequest request;

  // HOW TO PASS IN URL FROM PCL?????
            var url = new NSUrl("https://URL.com");
  ...............

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

How to save a QR code created with ZXing on device gallery folder like image?

$
0
0

Hi, I have created an QR code with next code and show correctly in my app but I need to export it like an image on the gallery folder device. I don't know how to do it.

barcode = new ZXingBarcodeImageView
    {
            HorizontalOptions = LayoutOptions.FillAndExpand,
            VerticalOptions = LayoutOptions.FillAndExpand,
    };

barcode.BarcodeFormat = ZXing.BarcodeFormat.QR_CODE;
    barcode.BarcodeOptions.Width = 500;
    barcode.BarcodeOptions.Height = 500;
    barcode.BarcodeValue = card_code;
    QRCode.Content = barcode;

Thanks in advanced.

Auto Size font for button text to fit in single line

$
0
0

Hello All,

I have a problem and kind of stuck on this.
I had 5 buttons which display at the bottom of the screen. (Android & ios)
The default font size is 14. I want to calculate the font size of all 5 buttons text to check they fit the screen size or not.
If they don't fit with the width of the screen then reduce the font size to 12 and try to display. If it still doesn't fit truncates the button text length and display with font size 14.

Button sets are in Grid and I have a button renderer which is using Control.TitleLabel.LineBreakMode = UILineBreakMode.WordWrap;
I can't change this wordwrap here because this renderer is been used in many places where text wrap is required.

This is another scenario where only 3 buttons are available and 2nd button still wraps in 2 lines.

Thank you

Is there any View Custom Renderer example that compactible with the current Android's Camera2 API ?

$
0
0

Looking at the View Custom Renderer example in the Xamarin's GitHub, while the example for creating the custom renderer is still valid, the given example for camera access for the Android platform is outdated, i even haven't checked the iOS's and UWP's side

Then, looking on to Xamarin.Android's "Basic Example" for Camera2 access, shows that the current version of Android's Camera API is changed too much, so much that it looks so 'alien' compared to the previous one. The needs of fragment, different classes for each of the callback, overloads here and there, and the list goes on. So difference, that some might finds all of those things, the Custom Renderer and the Camera API, is no longer compatible each other.

So, with all that being said. Is there any simple, not-overly-complex example on how to access Camera2 in Android on a exportable native view (ViewRenderer) for Xamarin.Forms View ?

Thank you

Viewing all 91519 articles
Browse latest View live


Latest Images

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