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

App crashes if you deny to access the camera in iOS, why?

$
0
0

Hi Everyone,
I am facing a very strange issue, When the app open it asks for the permission to access the camera and if I deny . And when i open for the camera the app crashes. Here is the snippet.

Device.BeginInvokeOnMainThread(async () =>
        {
            var action = await DisplayActionSheet("Add Photo", "Cancel", null, "Choose Existing", "Take Photo");

            if (action == "Choose Existing")
            {
                if (!CrossMedia.Current.IsPickPhotoSupported)
                {
                    await DisplayAlert("Photos Not Supported", ":( Permission not granted to photos.", "OK");
                    return;
                }
                var file = await Plugin.Media.CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions
                {
                    PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium,

                });


                if (file == null)
                    return;

                archieImg.Source = ImageSource.FromStream(() =>
                {

                    var stream = file.GetStream();
                    return stream;
                });
                archieImg.IsVisible = true;
                imgPet.IsVisible = false;
                MessagingCenter.Send(new PetModel() { ImageUrl = archieImg.Source }, "Image");
                asd = archieImg;

            }
            else if (action == "Take Photo")
            {

                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    await DisplayAlert("No Camera", ":( No camera avaialble.", "OK");
                    return;
                }

                var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium,
                    Directory = "Sample",
                    Name = "test.jpg",
                    AllowCropping = true
                });

                if (file == null)
                    return;
                archieImg.Source = ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    return stream;
                });
                archieImg.IsVisible = true;
                imgPet.IsVisible = false;
                MessagingCenter.Send(new PetModel() { ImageUrl = archieImg.Source }, "Image");
                asd = archieImg;
            }
        });

Thanks


办国外文凭学历认证Q/微29304199改GPA成绩英国卡迪夫大学文凭#卡大毕业证成绩单offer学位证书,雅思托福成绩单,在读证明/留信网认证/使馆认证公正Cardiff University,Pr

$
0
0

办国外文凭学历认证Q/微29304199改GPA成绩英国卡迪夫大学文凭#卡大毕业证成绩单offer学位证书,雅思托福成绩单,在读证明/留信网认证/使馆认证公正Cardiff University,Prifysgol Caerdydd

办国外文凭学历认证Q/微29304199改GPA成绩英国利兹大学文凭#Leeds毕业证成绩单offer学位证书,雅思托福成绩单,在读证明/留信网认证/使馆认证公正University of Leeds

$
0
0

办国外文凭学历认证Q/微29304199改GPA成绩英国利兹大学文凭#Leeds毕业证成绩单offer学位证书,雅思托福成绩单,在读证明/留信网认证/使馆认证公正University of Leeds

办国外文凭学历认证Q/微29304199改GPA成绩英国约克大学文凭#毕业证成绩单offer学位证书,雅思托福成绩单,在读证明/留信网认证/使馆认证公正 University of York

$
0
0

办国外文凭学历认证Q/微29304199改GPA成绩英国约克大学文凭#毕业证成绩单offer学位证书,雅思托福成绩单,在读证明/留信网认证/使馆认证公正 University of York

Navigate Problem (System.NullReferenceException Object reference not set to instance of an object)

$
0
0

As a result of an if evaluation, I want to open LoginPage. I really did a lot of search but I could not come to a conclusion. I need help.

*I am using Prism lib.
*MyTabbedPage is the mainpage.
*DownloadPage is child of MyTabbedPage but LoginPage is not.


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


[App.xaml.cs]
public partial class App : PrismApplication
{

    public static string AndroidExternalDirectory;
    public static string MyDateFormat { get; set; }

    public App(IPlatformInitializer initializer = null) : base(initializer)
    {
        InitializeComponent();
        MainPage = new MyTabbedPage();
        App.MyDateFormat = "dMMyyyy_hhmm";
    }

    protected override void RegisterTypes(IContainerRegistry containerRegistry)
    {
        containerRegistry.RegisterForNavigation<MyTabbedPage>();
        containerRegistry.RegisterForNavigation<DownloadPage>();
        containerRegistry.RegisterForNavigation<LoginPage>();
    }

    protected override void OnInitialized()
    {
    }
}

[DownloadPage.xaml.cs]
public partial class DownloadPage : ContentPage
{
public DownloadPage()
{
InitializeComponent();
BindingContext = new DownloadPageViewModel();
}
}


[DownloadPageViewModel.cs]

public class DownloadPageViewModel : BindableBase
{
    private string _title;
    public string Title
    {
        get
        {
            return _title;
        }

        set
        {
            SetProperty(ref _title, value);
        }
    }

    private readonly INavigationService _navigationService;
    private DelegateCommand _navigateCommand;
    public DelegateCommand NavigateCommand =>
        _navigateCommand ?? (_navigateCommand = new DelegateCommand(ExecuteNavigateCommand));
    public DownloadPageViewModel(INavigationService navigationService) 
    {
        Title = "DownloadPage";          
        _navigationService = navigationService;
    }
    async void ExecuteNavigateCommand()
    {
        await _navigationService.NavigateAsync("LoginPage");
    }

    public DownloadPageViewModel()
    {
        _parser = new HtmlParser();
        _webClient = new WebClient();
        Status = "Status: ";

        DownloadCommand = new DelegateCommand(async () =>
        {
            string extDir = App.AndroidExternalDirectory;
            string localFilesDir = Path.Combine(extDir, "InstagramPostFiles");

            if (!Directory.Exists(localFilesDir))
                Directory.CreateDirectory(localFilesDir);

            var doc = _parser.ParseDocument(_innerBody);
            var imgNodes = doc.QuerySelectorAll("img");
            var videoNodes = doc.QuerySelectorAll("video");

            await Task.Run(() =>
            {
                if (!_foundFileToDownload)
                {
                    Status = "Did not found any files in this link for downloading";

                    ExecuteNavigateCommand();
                }
            });

    }

How to make Scrollable Label in Collectionview Xamarin Forms

$
0
0

Hi there!
I have a Collectionview with fixed Row Height. Inside Collectionview there is Label with large description. I am trying to make this label scrollable. Can anyone help please.

I need Debugging with an API running in my PC (localhost)

$
0
0

I have a Xamarin Forms app that works against a asp net core web api and I need to debug it with the api running in my PC (localhost).
If I use the Uri "http://localhost:port/api/..." does not work.
Do you know how to solve this issue?

Is it possible to put a toolbar item in contentview?

$
0
0
<ContentPage.ToolbarItems>
    <ToolbarItem Order="Secondary"
                 Text="Share"
                 Command="{Binding ShareCommand}"
                 Priority="0"/>
</ContentPage.ToolbarItems>

Is it possible to do something like the above except with a ContentView? Or could someone please point out how to do something equivalent? So that one can make a list of views that will each have its own contextual menu (with the 3 dots button).

I noticed someone had asked this at the bottom of another thread but thought it may have been overlooked.


Null Coalescense property binding

$
0
0

Basically, I want to setup a binding that behaves like the following C# code:

this.Text = Control1.Text.IsNotNullOrEmpty() ? Control1.Text : Control2.Text

So, I want to bind my "Text" property to "Control1.Text" property IF it is not null and not an empty string, otherwise I want to use the "Control2.Text" property. Because "Control2.Text" might change it's value, I can't just use it as a default value when creating the binding. I don't see a way to do this, but if somebody knows an out of the box way to do this that would be great.

I've looked at the Binding and BindingBase classes and don't see a way to build a custom subclass that would allow me to do what I want.

Therefore, I think the only way I can do this is to create a "helper class" something like:

public class DoubleBinding<T>
{
    public T Value1 { get; set; }
    public T Value2 { get; set; }

    public T Value { get; }
}

With some logic that sets Value to the proper value any time Value1 or Value2 change. Then I would bind Value1 to Control1.Text and Value2 to Control2.Text and bind this.Text to just the Value property.

Is that my best option or is there a better way to do this?

How can I change the language of WebView?

$
0
0

I want to open every websites with in English language. (no matter the system language)
Let me give a simple example.
The system language of the user is Turkish. The language chosen by the user in the application settings is German. However, I want the WebView language to remain in English.

MIDI or Soundfonts for Xamarin Forms

$
0
0

Hello:
I have seen some Midi Nugets but, it does not work for Windows, Android and iOS, like:
Sanford.Multimedia.Midi
Managed-midi
Melanchall.DryWetMidi
and others.

Can you suggest me anyone that works and some examples to begin?
thank you very much

Custom search-list using Linq freezes.

$
0
0

Hi everybody.

I'm building a search - function in Xamarin (see code below):
I'm filling a Listview with data ( public async void FillSearchList()).
When the user writes in the entry, the datalines,
which content corresponds to the search-text,
are shown in the listview (through private void SearchList_OnTextChanged(object sender, TextChangedEventArgs e)).
The user picks a data-line ((private void SearchList_OnTextChanged(object sender, TextChangedEventArgs e))),
and this is being shown in the entry.
The problem is as follows:
First time the user picks a data-line, there are no problems. However, when picking a dataline for the second time,
the program freezes, Visual Studio 2019 freezes, and after a while the message below (in the picture) appears.

I searched for the error for a long time, but sadly -> no luck. In VS 2019 I tried to "Empty symbol cache" and chose "Microsoft Symbol Servers"
under Debug->Options->Debugging->Symbols (picture 2 below). It did not help.

Does anybody have an idea, how to fix this?
Friendly regards
nbs

Xaml-design:

.cs - code -file:

`using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace test_multi.FrameWork.CustomControls
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ListViewSearching : ContentView
{
ObservableCollection<KeyValuePair<string, string>> SearchDataList;
private DataManipulator dsg;
private AlertManager alert;
private string SqlFunction;
private string callMethod;
private string callObject;
public ListViewSearching()
{
InitializeComponent();
dsg = new DataManipulator();
}

    public ListViewSearching(String sqlFunction = "", string EntrySearchPlaceholder = "", string callingObject="", string callingMethod = "")
    {
        callMethod = callingMethod;
        callObject = callingObject;
        InitializeComponent();
         dsg = new DataManipulator();
        SqlFunction = sqlFunction;
        EntrySearch.Placeholder = EntrySearchPlaceholder;
        SearchDataList = new ObservableCollection<KeyValuePair<string, string>>();
        FillSearchList();
    }

    public async void FillSearchList()
    {
        try
        {
            SearchListValues poa = new SearchListValues();
            IDictionary<string, string> dict = new Dictionary<string, string>
            {
                { "COMPANY", Globals.Company }
            };
            var dataObjects = await dsg.GetDataAsync(SqlFunction, poa, dict, false);
            int count = 0;
            if (!dsg.IsNullOrEmpty(dataObjects))
            {
                // All sql-functions shall return 2 variables: ID and NAME
                foreach (SearchListValues searchVal in dataObjects)
                {
                    count++;
                    SearchDataList.Add(new KeyValuePair<string, string>(searchVal.ID, " " + searchVal.NAME));
                }
            }
        }
        catch (Exception ex)
        {
            alert = new AlertManager(Globals.ErrorOccured + Environment.NewLine + ex.Message.ToString(), Globals.AlertInfo);
        }
    }


    private void SearchList_OnTextChanged(object sender, TextChangedEventArgs e)
    {
        ListViewSearch.IsVisible = true;
        ListViewSearch.BeginRefresh();
        try
        {
            var dataSource = SearchDataList.Where(i => i.Key.ToLower().Contains(e.NewTextValue.ToLower()));
            if (string.IsNullOrWhiteSpace(e.NewTextValue))
                ListViewSearch.IsVisible = false;
            else if (dataSource.Any(s => string.IsNullOrEmpty(s.Key)))
                ListViewSearch.IsVisible = false;
            else
                ListViewSearch.ItemsSource = dataSource;
        }
        catch (Exception ex)
        {
            ListViewSearch.IsVisible = false;
        }
        ListViewSearch.EndRefresh();
        if (EntrySearch.Text.Trim().Equals(""))
            Globals._ValueChosen = "";
    }

    private void ListViewSearch_OnItemTapped(Object sender, ItemTappedEventArgs e)
    {       
        Globals.ChosenValues = (KeyValuePair<string, string>)e.Item;
        String listsd = Globals.ChosenValues.Key + " " + Globals.ChosenValues.Value;
        EntrySearch.Text = listsd;
        ListViewSearch.IsVisible = false;
        ((ListView)sender).SelectedItem = null;
    }

}

}`

delete option for gridview in xamarin forms

$
0
0

Hi,

I am working on xamarin forms application where I am using Phone and Tablet.
In phone I am using listview :For delete, edit, update funcationality In listview we have a MenuItem property ,
In tablet I am using Gridview (using flex layout) , I want same standard way of deleting the item as it is done in phone.(long press on an item delete ,edit option on header)

How can I achieve. Is customisation needed for this'? If yes can anybody share the code for this

Thanks

Cannot run android emulator from VS : stuck with "Select device" icon

$
0
0

Hi, after hours of research, i'm a bit disappointed. I found many similar cases but most of them were old or not solved.

When I start VS, I'm unable to select any Android emulator to deploy my app, stuck with "select device".

Since the beggining I used the same emulator, and everything was working fine. This problem appeared suddenly.

I can run emulators from the Android emulator manager perfectly but I am not able to deploy my app on it, I think VS cannot detect it running.
When I press F5 or Ctrl+F5, VS is asking me to create a new emulator (wich I do a few times but ye, when I run it, not detected)

I tried multiple things :

  • Delete/Re-install emulators. In my project I'm working on Pie 9.0 - Api, I also tried Android 10 and even Android 8.1 emulators, same problem.
  • Factory reset emulator
  • Use adb kill-server/start server (I cannot use "Restart ADB server" in Tools/Android, so I did it manually from console. I don't know why...)
  • Set my .Android as starting project

My case seems similar to "Visual Studio gets stuck trying to deploy the app to the emulator or the emulator does not appear as a debug target in other IDEs" from the "Troubleshoot the Visual Studio Emulator for Android" microsoft page, but to fix it, I need to use regedit and edit a key in HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Android SDK Tools, but I do not have Android SDK Tools folder.

The only things that partially solved my problem :

  • Full re-installation of Visual Studio
  • Re-install Android SDK Tools and Android Emulator from SDK package manager

Both allowed me to use my emulator as before. But when I restart my computer, the problem occurs again, with "Select device" stuck.
After mutliple tries, it is the only way I found to fix this problem. So the problem is should be caused by SDK packages.

I'm in trouble with it and tired spending hours to reinstall SDK Tools everytime.
Does someone have the same case ? Any idea to solve it ?

Navigating from one page to another blank content view is comes up

$
0
0

I'm navigating from one page to another using await NavigationService.NavigateAsync("index/root/mypage",params). The page gets navigated but there's blank content view from last page (i.e page 1) displayed while navigating from page 1 to page 2 and this issue is coming only in android.
The content view is used to display a list of values based on search condition in page1 and is shown/hidden based on conditions.

I'm not sure what is the issue. I checked the visibility of that popup in all the OnNavigatedTo() methods of page1 and 2 and its false.
Has anyone else faced this issue and were able to resolve it? Inputs appreciated. Thanks


doesn't show anything on my Android Emulator

$
0
0

Hello together,

I am quite new to Xamarin Forms and learning right now.
Maybe this is a really simple question but I couldn't find a solution in this Forum or by searching online for my issue.
I am using Visual Studio Version 16.5.4

When i use in my code there is no issue displayed when I compile.
But when I start my Android Emulator nothing is shown there.

It seems that either he does not find the picture or he just does not show it.

The url is working (checked several times).

Has anyone some suggested solutions?
Maybe there are just some configuration problems...

Thanks in advance!

This is my simple code which should be running but doesn't...

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

<ContentPage.Content>

        <Image Source="http://lorempixel.com/1920/1080/city/1"/>


    </StackLayout>
</ContentPage.Content>

Layout not updating in Android as expected

$
0
0

I dynamically configure a UI and for some reason in Andriod the views don't update as expected. When the device is rotated on Andriod the PageScrollView resizes but the child view zoomable doesn't (See screenshot). It works perfectly well on IOS. I have tried calling InvalidateMeasure on PageScrollView and that doesnt help.

foreach (var formPage in currentForm.pages)
                    {

                    var layout = new FormRelativeLayoutPage();
                    layout.HorizontalOptions = LayoutOptions.FillAndExpand;
                    layout.VerticalOptions = LayoutOptions.FillAndExpand;

                    layout.BackgroundColor = Color.Blue;

                    OptimisedImage image =null;

                        if (formPage.image != null)
                        {

                        var img = new MemoryStream(formPage.image);

                        var ImageStream = new MemoryStream();
                        img.CopyTo(ImageStream);
                        img.Dispose();

                        var byteArray = ImageStream.ToArray();

                        var imageSource = ImageSource.FromStream(() => new MemoryStream(byteArray));


                            image = new OptimisedImage
                            {
                                Aspect = Aspect.Fill,
                                Source = imageSource

                            };

                        layout.Children.Add(image,
        Constraint.Constant(0),
        Constraint.Constant(0),
        Constraint.RelativeToParent((parent) => { return parent.Width; }),
        Constraint.RelativeToParent((parent) => { return parent.Height; }));

                    }



                    addControls(layout,image, formPage);

                    var zoomable = new ContentView()//new PinchToZoomContainer()
                    {
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        VerticalOptions = LayoutOptions.FillAndExpand,
                        BackgroundColor = Color.Green,
                        //Content = layout
                    };

                    PageScrollView sv = new PageScrollView(currentForm)
                    {
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        VerticalOptions = LayoutOptions.FillAndExpand,
                        BackgroundColor = Color.Yellow,
                        Content = zoomable,
                        PageNo = formPage.pageNo
                };





                    pages.Add(sv);


                }

                CarouselViewControl cv = new CarouselViewControl
                {
                    ItemsSource = pages//, ItemTemplate = GetDataTemplate()
                    ,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions = LayoutOptions.FillAndExpand,
                    Orientation= CarouselViewOrientation.Horizontal

                };

                cv.ShowArrows = true;
                cv.ShowIndicators = true;
                cv.Scrolled += Cv_Scrolled;

                Content = cv

;

How to nest Tab views in Xamarin.Forms

$
0
0

I am trying to create this layout in Xamarin XAML but I cannot figure out how to combine TabView within a TabView. I want 3 main tabs in the bottom and for each page 1-2 subtabs. On each subtab I will need to have a ScrollView(I think thats the right element to use) with list items, which makes it even more complex. Like this picture:

Any idea/example or guidance of how to achieve this?

Android not following dark theme

$
0
0

I have a xamarin shell forms application. I am not trying to use colors or themes, I just want my app to follow device's default theme.
I see that windows app follows the dark and light theme based on system theme. But android app (android 10) always visible in light theme although device set to dark theme.

How i can use use device's default theme with minimum work on android?

Sqlite net multi tables

$
0
0

Hi,
I have some problems with the relations between my 3 tables. The 1 is "StatsEx" many to one => "Ex" many to many with "Trains". My table "Ex" is filled when the app is launch. But during the user utilisation, I would like to create new StateEx or Trains and update only the link with my table Ex.
Can you help me ? Because I don't know how to do it without update also my all table Ex.
Quent.

Viewing all 89864 articles
Browse latest View live


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