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

ToolbarItems do not look right in iOS

$
0
0

I have a Xamarin.Forms app with FreshMvvm, and am trying to use secondary ToolbarItems. Here is a part of my PageModel code:

  public override void Init(object initData)
  {
      CurrentPage.ToolbarItems.Add(new ToolbarItem() { Text = "About LATICRETE", Command = AboutCommand, Priority = 0, Order = ToolbarItemOrder.Secondary });
      CurrentPage.ToolbarItems.Add(new ToolbarItem() { Text = "Call LATICRETE", Command = CallCommand, Priority = 0, Order = ToolbarItemOrder.Secondary });
      CurrentPage.ToolbarItems.Add(new ToolbarItem() { Text = "Email Technical Support", Command = EmailTechSupportCommand, Priority = 0, Order = ToolbarItemOrder.Secondary });
      CurrentPage.ToolbarItems.Add(new ToolbarItem() { Text = "Visit LATICRETE Website", Command = VisitWebsiteCommand, Priority = 0, Order = ToolbarItemOrder.Secondary });

For Android, after pressing the hamburger button, the menu looks like I expect:

enter image description here

But at iPhone, it is quite different:

enter image description here

As you can see, there is no hamburger button, and all the ToolbarItems are placed horizontally next to each other, and as they do not fit withing the width of the screen, they overlap. I realize that this is the normal behavior for iOS, and yet it is not acceptable for me. Is there any way to fix it?


Master-Detail: how to add a command instead of a detail page

$
0
0

I have a Xamarin.Forms app with FreshMvvm. I am trying to use Master-Detail architecture, like this:

    var masterDetailNav = new FreshMasterDetailNavigationContainer();

    masterDetailNav.Init("Menu");

    masterDetailNav.AddPage<AboutPageModel>("About", null);

    masterDetailNav.AddPage<PageModels.CoverageCalculator.CoverageCalculatorPageModel>("Coverage Calculator", null);

    MainPage = masterDetailNav;

This is good, but I need to add navigation elements that would do something OTHER than opening detail pages. E.g. I may need to open some website in the browser or make a call etc. Is it doable, and if so, how?

HOW TO IMPLEMENT WKWEBVIEW IN XAMARIN FORMS

$
0
0

Hello guys,

Since UIWebview is deprecated, how can I implement WKWebview in my xamarin forms mobile app.

Thank you.

Content Page Secondary Toolbar Items in iOS same as Android

$
0
0

I am using secondary toolbar items in my content page. I want the same menu items in iOS as in android. By default it is showing under navigation bar. How can I achieve this.

Dismiss AlarmClock

$
0
0

Hello I have a problem in Xamarin Forms (Visual Studio 2017) on Android.
I use AlacmClock Intent to create an alarm like this:
private void SetAlarmClock(int minutes, string message)
{
try
{
string ringtoneUri = App.UserSettings.GetSettings("RingtoneUri");
DateTime alarmTime = DateTime.Now;
alarmTime = alarmTime.AddMinutes(minutes);
Intent intent = new Intent(AlarmClock.ActionSetAlarm);
intent.PutExtra(AlarmClock.ExtraHour, alarmTime.Hour);
intent.PutExtra(AlarmClock.ExtraMinutes, alarmTime.Minute);
intent.PutExtra(AlarmClock.ExtraMessage, message);
intent.PutExtra(AlarmClock.ExtraSkipUi, true);

            if (!string.IsNullOrEmpty(ringtoneUri))
                intent.PutExtra(AlarmClock.ExtraRingtone, ringtoneUri);
            context.StartActivity(intent);
        }
        catch (Exception ex)
        {
            App.UserSettings.WriteProtocol("SetAlarmClock Exception: " + ex.Message);
        }
    }

But I have also method for dismiss this alarm but it don't work:
private void DismissAlarmClock(string message)
{
try
{
Intent intent = new Intent(AlarmClock.ActionDismissAlarm); // This Intent can be used only for API 23 and higher (Android 6.0)
intent.PutExtra(AlarmClock.ExtraAlarmSearchMode, AlarmClock.AlarmSearchModeLabel);
intent.PutExtra(AlarmClock.ExtraMessage, message);
intent.PutExtra(AlarmClock.ExtraSkipUi, true);
context.StartActivity(intent);
}
catch (Android.Content.ActivityNotFoundException)
{
App.UserSettings.WriteProtocol("DismissAlarmClock AlarmClock.ActionDismissAlarm is not supported on Android 5.1 and lower!");
}
catch (Exception ex)
{
App.UserSettings.WriteProtocol("DismissAlarmClock Exception: " + ex.Message);
}
}

Problem 1: it dismisses the alarm not always
Problem 2: Nevertheless I use intent.PutExtra(AlarmClock.ExtraSkipUi, true); it opens always Alarm/Watches App on Android.

I have seen some examples on internet with AlarmManager and PendingIntent but this also don't works in my App.
Thanks.

Xamarin Forms: Custom webview is not working in IOS

$
0
0

I am using Custom Webview for solving ITMS-90809: Deprecated API Usage - Apple will stop accepting submissions of apps that use UIWebView APIs. and parsing HTML data.

My Code:

MyWebView.cs

using Xamarin.Forms;

namespace CustomWebview
{
    public class MyWebView : WebView
    {
        public static readonly BindableProperty UrlProperty = BindableProperty.Create(
        propertyName: "Url",
        returnType: typeof(string),
        declaringType: typeof(MyWebView),
        defaultValue: default(string));

        public string Url
        {
            get { return (string)GetValue(UrlProperty); }
            set { SetValue(UrlProperty, value); }
        }
    }
}

IOS

using CustomWebview;
using CustomWebview.iOS;
using WebKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(MyWebView), typeof(MyWebViewRenderer))]

namespace CustomWebview.iOS
{
    public class MyWebViewRenderer : ViewRenderer<MyWebView, WKWebView>
    {
        WKWebView _wkWebView;

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

            if (Control == null)
            {
                var config = new WKWebViewConfiguration();
                _wkWebView = new WKWebView(Frame, config);
                SetNativeControl(_wkWebView);
            }
            if (e.NewElement != null)
            {
                Control.LoadHtmlString(Element.Url, null);   //use this code instead
                //Control.LoadRequest(new NSUrlRequest(new NSUrl(Element.Url)));
            }
        }
    }
}

When I open the page having MyWebView the page redirects to Main.cs and shows the below exception.

enter image description here

I have uploaded a sample project here.

After Email confirm , User can sign up Information. how to do that?

$
0
0


After i clicked confirm button.

After I confirmed my pin number for Email validation,

And then i can register my Acount,..
how do i make it ?

right now, even though i did not clicked confirm button, i can register my information.

how do i make if condition that i have to click confirm button then register process working?

  <Entry x:Name="Entry_Email"  Placeholder="Email"></Entry>
        <Button x:Name="Confirlemailinfo" Text="Confirmed Email" Clicked="Confirm_email"/>





    public  void Confirm_email(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Entry_Email.Text))
            { 
            try
            {

                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                mail.From = new MailAddress("sjin@pkim.com");
                mail.To.Add(Entry_Email.Text);
                mail.Subject = "Email Confirmation";
                mail.Body = "Confirm pin code:" + number;

                SmtpServer.Port = ;
                SmtpServer.Host = "smtp.gmail.com";
                SmtpServer.EnableSsl = true;
                SmtpServer.UseDefaultCredentials = false;
                SmtpServer.Credentials = new System.Net.NetworkCredential("");

                SmtpServer.Send(mail);
            }
            catch (Exception ex)
            {
                DisplayAlert("Faild", ex.Message, "OK");
            }
            PopupNavigation.Instance.PushAsync(new MyPopupPage(number));
            }
        else
            DisplayAlert("please", "Enter Email", "OK");
    }

To open another app from xamarin forms app

$
0
0

From a xamarin forms app, when we click a button is it possible to open an app in power apps (with SSO also) ? Could anyone give me suggestions.


How to share an url to my app?

$
0
0

I want to share an url, the url of page where I am, to my Xamarin Forms App (Android and iOS).

And when I',m going to share this url...

I want that my app appears into the share options list, to send this url to my app to a specific page, beacause I want to use this url strings into the app.

Uploading multiple Image Using FlowlistView

$
0
0

Hi Xamarin Forum

can I get a little help I want to upload my multiple image to a folder in my web server can some body help me here is my current codes

XAML

<ScrollView>
            <StackLayout>
                <StackLayout Orientation="Horizontal">
                    <Label Text="CREATE A POST" Margin="9,20,0,0" FontFamily="Raleway-Bold" FontAttributes="Bold" FontSize="16"></Label>
                </StackLayout>
                <Label Text="Title" FontFamily="Raleway-Black" Margin="20,0,20,0"></Label>
                <controls:CustomEntry x:Name="HouseName" TextColor="Black" Margin="20,0,20,0" BackgroundColor="Transparent" FontAttributes="Bold" WidthRequest="200"/>
                <StackLayout Orientation="Horizontal">
                    <StackLayout>
                        <Label Text="Year Built" FontFamily="Raleway-Black" Margin="20,0,20,0"></Label>
                        <controls:CustomEntry x:Name="yearbuiltentry" TextColor="Black" Margin="20,0,0,0" BackgroundColor="Transparent" FontAttributes="Bold" WidthRequest="150"/>
                    </StackLayout>
                    <StackLayout>
                        <Label Text="Price" FontFamily="Raleway-Black" Margin="20,0,10,0" HorizontalOptions="End"></Label>
                        <controls:CustomEntry x:Name="HousePrice" TextColor="Black" Margin="20,0,0,0" BackgroundColor="Transparent" FontAttributes="Bold" WidthRequest="190"/>
                    </StackLayout>
                </StackLayout>
                <Label Text="Location" FontFamily="Raleway-Black" Margin="20,0,20,0"></Label>
                <controls:CustomEntry x:Name="HouseLocation" TextColor="Black" Margin="20,0,20,0" BackgroundColor="Transparent" FontAttributes="Bold" WidthRequest="200"/>
                <Label Text="Description" FontFamily="Raleway-Black" Margin="20,0,20,0"></Label>
                <controls:CustomEntry x:Name="postContent" TextColor="Black" Margin="20,0,20,0" BackgroundColor="Transparent" FontAttributes="Bold" WidthRequest="200"/>
                <Label Text="IMAGES" FontAttributes="Bold" FontSize="16" FontFamily="Raleway-Bold" Margin="20,0,20,0"/>
                <StackLayout Orientation="Horizontal" HeightRequest="100" Margin="20,0,0,0">
                    <flv:FlowListView FlowColumnCount="3" x:Name="listItems" 
                        SeparatorVisibility="None"
                        HasUnevenRows="false" RowHeight="300">
                        <flv:FlowListView.FlowColumnTemplate>
                            <DataTemplate >
                                <ffimageloading:CachedImage  DownsampleToViewSize="true" x:Name="ImageContainer" AbsoluteLayout.LayoutFlags="All" HeightRequest="300" AbsoluteLayout.LayoutBounds="0,0,1,1" Source="{Binding .}"  Aspect="AspectFill" HorizontalOptions="FillAndExpand">
                                </ffimageloading:CachedImage>
                            </DataTemplate>
                        </flv:FlowListView.FlowColumnTemplate>
                    </flv:FlowListView>
                    <Button TextColor="White" BackgroundColor="Gray"  Text="+" Clicked="Handle_Clicked" Margin="5,0,10,0"/>
                </StackLayout>
                <controls:CustomEntry x:Name="FloorArea" TextColor="Black" Margin="20,10,20,10" BackgroundColor="Transparent" Placeholder="Size in Sq Ft" FontAttributes="Bold" WidthRequest="200"/>
                <Label Text="LIVING SPACE" FontFamily="Raleway-Black" Margin="20,0,10,0" FontAttributes="Bold"></Label>
                <StackLayout>
                    <StackLayout Orientation="Horizontal">
                        <Image Source="Bedroom.png" WidthRequest="50" HeightRequest="50"/>
                        <Label Text="Bedroom" FontFamily="Raleway-Black"/>
                        <Label BindingContext="{x:Reference inc_stepper}" Text="{Binding Value}" x:Name="Bedroom"/>
                        <Stepper Minimum="0" Maximum="4" x:Name="inc_stepper" Increment="1" StyleClass="stepperClass" />
                    </StackLayout>
                    <StackLayout Orientation="Horizontal">
                        <Image Source="Bath.png" WidthRequest="50" HeightRequest="50"/>
                        <Label Text="Baths" FontFamily="Raleway-Black"/>
                        <Label BindingContext="{x:Reference inc_stepper2}" Text="{Binding Value}" x:Name="BathToilet" />
                        <Stepper Minimum="0" Maximum="4" x:Name="inc_stepper2" Increment="1" Margin="100,0,0,0" />
                    </StackLayout>
                    <StackLayout Orientation="Horizontal">
                        <Image Source="Floors.png" WidthRequest="50" HeightRequest="50"/>
                        <Label Text="Floors" FontFamily="Raleway-Black"/>
                        <Label BindingContext="{x:Reference inc_stepper3}" Text="{Binding Value}" x:Name="Storey" />
                        <Stepper Minimum="0" Maximum="4" x:Name="inc_stepper3" Increment="1" Margin="100,0,0,0" />
                    </StackLayout>
                </StackLayout>
                <Label Text="AVAILABLE FOR" FontFamily="Raleway-Black" Margin="20,0,10,0" FontAttributes="Bold"></Label>
                <Button Text="UPLOAD" Clicked="Upload_File"/>
            </StackLayout>
        </ScrollView>

CodeBehind

public partial class PostCreationPage : ContentPage
{
//public List postslist;
//string json;
List _images = new List();
public PostCreationPage()
{
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");
    }

    private MediaFile _mediaFile;

    async void Handle_Clicked(object sender, System.EventArgs e)
    {

        // await DependencyService.Get<IMediaService>().OpenGallery();

        //_mediaFile.GetStream();
        //var memoryStream = new MemoryStream();

        //if (Device.RuntimePlatform == Device.iOS)
        //{
        //    //If the image is modified (drawings, etc) by the users, you will need to change the delivery mode to HighQualityFormat.
        //    bool imageModifiedWithDrawings = false;
        //    if (imageModifiedWithDrawings)
        //    {
        //        await GMMultiImagePicker.Current.PickMultiImage(true);
        //    }
        //    else
        //    {
        //        await GMMultiImagePicker.Current.PickMultiImage();
        //    }

        //    MessagingCenter.Unsubscribe<App, List<string>>((App)Xamarin.Forms.Application.Current, "ImagesSelectediOS");
        //    MessagingCenter.Subscribe<App, List<string>>((App)Xamarin.Forms.Application.Current, "ImagesSelectediOS", (s, images) =>
        //    {
        //        //If we have selected images, put them into the carousel view.
        //        if (images.Count > 0)
        //        {
        //            listItems.ItemsSource = images;

        //        }
        //    });
        //}
        //If we are on Android, call IMediaService.
        if (Device.RuntimePlatform == Device.Android)
        {
            DependencyService.Get<IMediaService>().OpenGallery();

            MessagingCenter.Unsubscribe<App, List<string>>((App)Xamarin.Forms.Application.Current, "ImagesSelectedAndroid");
            MessagingCenter.Subscribe<App, List<string>>((App)Xamarin.Forms.Application.Current, "ImagesSelectedAndroid", (s, images) =>
            {
                //If we have selected images, put them into the carousel view.
                if (images.Count > 0)
                {
                    listItems.ItemsSource = images;   
                }
            });
        }

    }

    private List<string> CompressAllImages(List<string> totalImages)
    {
        int displayCount = 1;
        int totalCount = totalImages.Count;
        List<string> compressedImages = new List<string>();
        foreach (string path in totalImages)
        {
            compressedImages.Add(DependencyService.Get<ICompressImages>().CompressImage(path));
            displayCount++;
        }
        return compressedImages;
    }

    private async void Upload_File(object sender, EventArgs e)
    {
        List<string> imagePaths = _images;

        string userfirstname = App.FirstName;
        var page = new LoadingPage();
        var content = new MultipartFormDataContent();
        var imageName = Path.GetFileName(imagePaths.ToString());
        await PopupNavigation.Instance.PushAsync(page);

        var httpClient = new HttpClient();

        var Absolutepath_1 = "http://167.86.109.234:8087/Uploads";

        Pipeline databaseConnect = new Pipeline();
        try
        {
            SqlCommand sqlInsert = new SqlCommand("INSERT INTO tablename(House_Name, Post_Content, Photo, Photo_2, Photo_3, Photo_4, Location, Floor_Area, Price, Bedroom, Toilet_And_Bath, Uploader, Date_Uploaded) " +
            "VALUES(@HouseName, @PostContent, @Photo, @Photo2, @Photo3, @Photo4, @Location, @Price, @Floor, @Bedroom, @TB,  @Uploader, @DateUploaded)", databaseConnect.connectDB());
             {
                sqlInsert.Parameters.Add("@Photo", SqlDbType.VarChar);
                sqlInsert.Parameters.Add("@Photo2", SqlDbType.VarChar);
                sqlInsert.Parameters.Add("@Photo3", SqlDbType.VarChar);
                sqlInsert.Parameters.Add("@Photo4", SqlDbType.VarChar);

                foreach (var value in imagePaths)
                {
                    string extensionName = ".jpg";
                    string pathNames = Absolutepath_1 + "/" + Path.GetFileName(value) + extensionName;
                    sqlInsert.Parameters["@Photo"].Value = pathNames;
                    sqlInsert.Parameters["@Photo2"].Value = pathNames;
                    sqlInsert.Parameters["@Photo3"].Value = pathNames;
                    sqlInsert.Parameters["@Photo4"].Value = pathNames;

                }
                sqlInsert.Parameters.AddWithValue("@Uploader", userfirstname);
                sqlInsert.Parameters.AddWithValue("@DateUploaded", DateTime.Now);
                sqlInsert.Parameters.AddWithValue("@Location", HouseLocation.Text);
                sqlInsert.Parameters.AddWithValue("@Price", HousePrice.Text);
                sqlInsert.Parameters.AddWithValue("@Floor", FloorArea.Text);
                sqlInsert.Parameters.AddWithValue("@Bedroom", Bedroom.Text);
                sqlInsert.Parameters.AddWithValue("@HouseName", HouseName.Text);
                sqlInsert.Parameters.AddWithValue("@TB", BathToilet.Text);
                sqlInsert.Parameters.AddWithValue("@Storey", Storey.Text);
                sqlInsert.Parameters.AddWithValue("@PostContent", postContent.Text);

                int i = sqlInsert.ExecuteNonQuery();

                await PopupNavigation.Instance.PopAsync();
                await Navigation.PopAsync();

                await DisplayAlert("Success", "Uploaded to Database.", "OK");
             }

        }
        catch (Exception ex)
        {

        }
    }

    internal static StreamContent CreateFileContent(Stream stream, string fileName, string contentType)
    {
        var fileContent = new StreamContent(stream);

        fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") {
            Name = "\"files\"",
            FileName = "\"" + fileName + "\""
        };

        return fileContent;
    }

}

Thanks in advance

How to pass parameter from Rg.Plugin.Popup to content page?

$
0
0

When I am going to pass parameter from Rg.Plugin.Popup page to a Content page,the content page will reload
so how to accept parameters from popup page to content page?

Master Detail on Android (Prism) - Accessing Camera via Detail disables Hamburger Menu button

$
0
0

HI,

I have a MasterDetail Page with a button to access the Camera or Gallery on several of the Detail Pages. I'm noticing that upon exiting the Camera/Gallery the Hamburger Menu button is disabled and the only way to access the Menu is by swiping from the left of the screen.

Has anyone come across this behaviour and found a workaround?

Thanks in advance

How read metadata with crossmediamanager in audio stream.

$
0
0

public async void PlayStream()
{
var mediaItem = await CrossMediaManager.Current.Play("URL");
mediaItem.MetadataUpdated += (sender, args) => {
title = args.MediaItem.Title;
};
}
Everything works correctly with an mp3 file, while metadata is not received with a streaming stream. Why ?

How to capture (within time interval) GeoLocation without button click (run as background service)

$
0
0

How to capture GeoLocation (latitude, longitude and current date and time) without button click, run like background service/program within some time interval or when location is changed using Xamarin form.

Changing MainPage between AppShell and NagivationPage breaks app screen.

$
0
0

Hello.
I found an issue of Xamarin.Forms 4.0 on Changing MainPage between AppShell and NagivationPage.

It is very easy to reproduce the issue.

1) Create a Xamarin.Forms 4.0 solution with AppShell Template

2) Add a Content Page (LoginPage.xaml)

3) Change MainPage at App.xaml.cs like this;

        public App()
        {
            InitializeComponent();

            DependencyService.Register<MockDataStore>();
            //MainPage = new AppShell();
            MainPage = new NavigationPage(new LoginPage());
        }

4) Change MainPage in LoginPage like this;

        private void LoginButton_Clicked(object sender, EventArgs e)
        {
            Application.Current.MainPage = new AppShell();
        }

5) Add a MenuItem in AppShell and Add Logout method like this;

  private void LogoutMenuItem_Clicked(object sender, EventArgs e) {
           Application.Current.MainPage = new NavigationPage(new Views.LoginPage());
  }

6) Bulid and run the app

7) “Login and Logout” action makes app screen broken like the attached screen shot file.

App MainPage is changed like this;

NavigationPage(new Views.LoginPage()) => new AppShell() => NavigationPage(new Views.LoginPage()).

It is very common pattern to implement Login function and I am regarding it must be a XF bug.

It is very easy to reproduce, but I attached my source code for the convenience

My testing environment is Visual Studio 2019 on Windows 10 Pro and I updated XF 4.0 up to date.

Is there any solution or workaround to solve the issue?

Best regards.


Forms to Native and back to Forms and still maintain the Forms navigation stack?

$
0
0

Hi All
How can I maintain the navigation stack in following scenario

  1. Page 1 on Forms

  2. Page 2 on IOS using page renderers

  3. Page 3 on IOS is a UIViewController (Lets call this ProcessImagePage) created & called from custom renderer from step 2

  4. When Page 3 is done processing I navigate back to Page 4 on forms via following code:

var secondViewController = App.GoToPostScanPage().CreateViewController(); NavigationController.PushViewController(secondViewController, true);

The navigation stack is like this
Page 1-> ProcessImagePage-> Page 3

Is there a way I can maintain the navigation stack to be
Page 1-> Page 2-> Page 3?

More details on my approach available on this SO post:

http://stackoverflow.com/questions/28084453/xamarin-forms-to-native-back-query

Thanks
Supreet

Button States

$
0
0

How i can make states in button?
Example:
0 state - transparent button background and string label = null
1 state - green button background and string label = label
2 state - red button background and string label = !label

There will be more such buttons 10

Labels and Editor controls crash when text is set with large number of characters per line

$
0
0

In Xamarin Forms 4.4 if you have a really long string with no line breaks it crashes both the editor and label controls

Is there any way to implement Stripe card widget in the Xamarin.Forms?

IDEA: Reduce APK Size by compressing the libraries and uncompressing them in runtime like routers

$
0
0

Hello I think we can reduce the final apk size by compressing the used libraries and uncompressing them in runtime just like routers or cablemodems do... They use lzma compression for the firmware and have a small bootloader to uncompress it...

What do you think about it?

Viewing all 77050 articles
Browse latest View live