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

How to search for removable USB drive and get all content inside it?

$
0
0

I'm using VS2017 Community to build Xamarin.Forms .NET Standard app in C#. The app will be running on android device. I want to detect USB drive is mounted and get all files path inside USB which is images and video. I cannot get the idea of how to do it. I have search some of the question but I cannot make it works.

My app will be running on below setup:-

Solution from below not work OR I'm doing it the wrong way:-
https://stackoverflow.com/a/19982338/3436326
https://stackoverflow.com/a/17085125/3436326

I also try to use File[] externalStorageFiles=ContextCompat.getExternalFilesDirs(this,null); but get error on ContextCompat not exist in current context.


TouchTracking input offset

$
0
0

Hey I'm playing around with a combination of Touch tracking and SkiaSharp libraries.

I've got it all working fine but there seems to be a curious situation with the cordinates being returned by the touch input. My little application takes point X and point Y and updates the canvas text object to the cordinates but only at 50% the value they should be.

Here I am gathering the coordinates that have been touched on screen:

        void OnTouchEffectAction(object sender, TouchActionEventArgs args)
        {
            userMadeInput = true;

            xTouch = args.Location.X;
            yTouch = args.Location.Y;
        }

Then I apply it to the text object and refresh the screen:

         yText = yTouch;
         xText = xTouch;

 //Debug Text
            canvas.Save();
            canvas.Clear(SKColors.MediumSeaGreen);

            canvas.DrawText("x: " + xText + "| y: " + yText, xText, yText, textPaint);

            canvas.Restore();

Then in a test, I run my finger down the screen but the values are coming in half of the value they should be.
ie: screen position 50 returns 25
or screen position 250 returns 125

I rectified the issue by multiplying the positions by two and that works great on my physical Android phone.

             yText = yTouch * 2;
             xText = xTouch * 2;

Now if I go to test it in the VS Android emulator I get the same issue. But for it to work on the emulator, I now need to multiply it by 3.

What's going on with the resolution here?

Editor not sizing properly

$
0
0

I would like the Editor to autoSize and display the whole text. What happens now is when I display a large text in the editor (Lorem Ipsum....) the editor displays only 1 or 1 and a half line and I have to scroll inside the Editor. When I start editing and add a newline/enter, the Editor size jumps to the correct size displaying the whole text.

For iOS I have also tried creating a customRenderer (iOS) setting Control.ScrollEnabled = false; and Control.SizeToFit(); and that seems to work the first time but after editing a while, the Editor size jumps back to 1 line. tapping return on the keyboard the editor jumps back to full size. The AutoSize property does not seem do much either.

On Android it is a different story: the text is visible but it doesn't fit in the editor entirely, I have a feeling that the Editor height is calculated by multiplying the number if linbreaks, which results in the text never fitting the control because it does not wrap text.

Does anybody know how to solve this issue?

@Microsoft PS: I am unable to post a question in Chrome (on Mac) anymore? Buttons don't get disabled and the "Category does not exist message" does not display. It does work in Safari.

macOS: acceptsFirstMouse

$
0
0

Hi,

I ask this, because the problem is only when I use Xamarin.Forms in macOS.

When my app (window) has no focus, i have to activate the window and then I can press a button. I want to press the button without activating it first.
There is a acceptsFirstMouse method which can be overridden in NSView. But I think Xamarin.Forms is building the NSView?

Have someone an Idea how can i reach the behavior?

Can you cast MaterialTextField as an Entry?

$
0
0

I have successfully followed the instructions (mikalaidaronin.info/blog/posts/xamarin-forms-password-autofill) to implement a Password AutoFill effect on Xamarin.Forms Entry elements - this is behaving properly on both Android and iOS platforms. However, I am unable to get the effect to work when I use it on the MaterialTextField element from the XF.Material (github.com/Baseflow/XF-Material-Library) library.

I believe that the issue comes down to the native effect implementation for both iOS and Android, where I cast the xamarin form elements to native platform elements; in Android I need to use an EditText element, while in iOS I need to use a UITextField element. I haven't been able to cast the MaterialTextField to either of these elements.

Is this even possible using the XF.Material library element like this? Any suggestions would be greatly appreciated! Thank you to everyone in this community!

How can I display an image in a list?

$
0
0

I want to put a binded image and in my viewmodel pass the image to ImageSource.

This my Code.

Code XAML

Code ViewModel

And this my result
I get blank

OnAppearing method is not performing the functionality

$
0
0

For the first time I'm restricting the onAppearing() Method. I need to call the onAppearing() when I change the tab. For that, I'm using OnCurrentPageChanged() to call the onAppearing() Method.
When I change the tab, I'm calling the OnCurrentPageChanged() and giving them access to run the onAppearing() functionality.onAppearing() is calling and also debugging but data is not binding to my screen.

TabbedPage code:

public partial class VendorScheduleTabbedPage : Xamarin.Forms.TabbedPage
    {
       public int isCount;
        public VendorScheduleTabbedPage ()
        {
            InitializeComponent ();
            Xamarin.Forms.Application.Current.Properties["dayOnAppear"] = false;
            On<Android>().SetBarItemColor(value: Color.FromHex("#6699FF"));
            On<Android>().SetBarSelectedItemColor(value: Color.Orange);
        }
        override protected void OnCurrentPageChanged()
        {
            isCount = 1;
            if (this.CurrentPage.Title == "Week")
            {
                Xamarin.Forms.Application.Current.Properties["weekOnAppear"] = true;

            }
            if (this.CurrentPage.Title == "Month")
            {
                Xamarin.Forms.Application.Current.Properties["monthOnAppear"] = true;
            }
            base.OnCurrentPageChanged();
        }
    }
}

WeekChild Page code:

     public WeekSchedulePage()
            {
                InitializeComponent();
                NavigationPage.SetHasNavigationBar(this, false);
                timeSlot = new List<VendorScheduleTimeSlot>();
                scheduleSlots = new List<VendorScheduleTimeSlot>();
                lstVendorsData = new List<ScheduledCustomersVM>();
                SortedList = new List<ScheduledCustomersVM>();
                scheduledCustomersList = new List<ScheduledCustomersVM>();
                rescheduledCustomersList = new List<RescheduledCustomersVM>();
                ConfirmBtn.IsVisible = true;
                ConfirmBtn.IsEnabled = false;

                vendorDayAndHoursDataVM = new VendorDayAndHoursDataVM();
                lstDaysAndHours = new List<VendorDayAndHoursDataVM>();
                lstQuestionsData = new List<VendorQuestionsDataVM>();
                overlay.IsVisible = false;
                Alert.IsVisible = false;

            }
    protected override void OnAppearing()
        {
            var isAppear = Convert.ToBoolean(Application.Current.Properties["weekOnAppear"].ToString());
            if (isAppear == true)
            {
                ConfirmBtn.IsVisible = true;
                ConfirmBtn.IsEnabled = false;

                overlay.IsVisible = false;
                Alert.IsVisible = false;

                Application.Current.Properties["dayOnAppear"] = true;
                Application.Current.Properties["monthOnAppear"] = true;
                ConfirmBtn.IsEnabled = false;
                scheduledCustomersList.Clear();
                rescheduledCustomersList.Clear();

                presentWeekDay.Text = DateTime.Now.ToString("dddd, dd MMMM yyyy");

                currentDayName = DateTime.Now.DayOfWeek.ToString();

                weekwiseTimeslotClick();

                base.OnAppearing();
            }
        }

Here I need to call OnApearing() method first instead of the parameterized constructor. And OnCurrentPageChanged() and OnApearing() are not calling at time.

http://xam150.azurewebsites.net/api/books/Login - Is this server still up or no?

$
0
0

I cannot connect to the URL that we are supposed to be using for XAM 150 exercises. Is the web server still up and running or no?


How do I set the font family of a label, platform to platform.

$
0
0

I'm a beginner in Xamarin and xml. I know a some C#. I'm trying to set the font of my Xamarin Forms application on the android version specifically, that way I can get a monospace font (Droid Sans Mono). I've looked around at a lot of threads about fonts and OnPlatform and data bindings, but I'm a little bit lost. I'm pretty sure Font.FontFamily is read-only as well.

here are some examples of things I have tried:
Label1.FontFamily = Device.OnPlatform("MarkerFelt-Thin", "Droid Sans Mono", "Comic Sans MS");

<Label x:Name="Label1" Text="" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"> <Label.FontFamily> <OnPlatform x:TypeArguments="String"> <On Platform="Android">Droid Sans Mono</On> </OnPlatform> </Label.FontFamily> </Label>

Change Image Source in Code in Xamarin Forms

$
0
0

I have an Image that is too small for Tablets so i need to change it with another Image in Code
and i found that i can write this :

c# :

HeaderImg.Source = "locationPng.png";

but i see no one is doing this because it is a **bad practice ** !
Why is it a bad practice and what is the right way to change Image Source in Code ? Or is it a good solution ?

my Xaml :

** Image x:Name="HeaderImg" Source="LogoBG012" Grid.Row="0" **

my C# :

if (Device.Idiom == TargetIdiom.Tablet)
{
// Code needed
}
else if (Device.Idiom == TargetIdiom.Phone)
{
HeaderImg.Aspect = Aspect.AspectFit;
}

eliteKit: Xamarin Forms UI Kit

$
0
0

Hi guys,

I'm proud to announce the first release of the eliteKit Xamarin Forms UI Kit. It's a collection of 20 UI elements made with SkiaSharp to make it much easier creating and design your next app.

You can find all informations about this project under www.eliteKit.de.

A free LITE version is available with 10 UI elements. There is also a PRO version containing all 20 UI elements. We're planning to create a lot of more UI elements in future, as we're a team of 3 people creating, developing and designing awesome elements. Lifetime updates are for free available.

With a built in community you can ask any questions related to eliteKit to staffs or other community members. We're giving our best to answer and help you immediately or as fast as possible. You can even ask us to create new UI elements or suggest us any changes to existing elements. For any found bug's we'd be happy to get noticed about it in the eliteKit bug reports category.

Feel free to have a look on our homepage under www.eliteKit.de

How can I show a notification? (popup) like facebook, whatsapp, spotify daoes it

$
0
0

At the same way spotify, facebook, whatsapp, instagram show you a notification (popup) when you recive a message, I need to show a message in my app even if this it is off. Any idea?

How to create Linear reveal animation in xamarin form?

$
0
0

Hi, i want to create linear reveal animation in xamairn form, i have reference of circle reveal animation source code but need to convert into linear reveal animation. I have tried but field any one please help me.

Circle reveal animation layout source code reference: https://github.com/mariusmuntean/FormsRevealer

Place Image on Frame's Border

$
0
0

Hi,

How can I place an image on the Frame border centered just like the Bill gates and USA flag here in the attached image?

Thanks,
Jassim

Selecting a StackLayout in a ListView is very difficult - How can it be made easier?

$
0
0

The DataTemplate of my ListView contains a StackLayout. That StackLayout has a few child views. Labels, Entrys, DateTimePickers, etc. I would expect a single or double tap anywhere in rectangular bounds of the StackLayout to actually "highlight" the entire StackLayout. However, it only happens if I tap in an area above or below my other view controls (is that the appropriate term?) in the StackLayout. How can I get the StackLayout to highlight everything even when tapping on the child views?

The only way I can think of at the moment is to set tap handlers (GestureRecognizers) on all the child controls that would have a single line of code to set the ListView's SelectedItem property to the parent StackLayout. Is that the best solution here?


Xamarin forms: How to parse HTML Data having video links?

$
0
0

I have video links(Vimeo video) and normal texts in my HTML data. I am using Xam.Plugin.HtmlLabel for parsing the HTML data. But it is not effective, the links are not clickable on the iPhone. Also, the video links are missing when coming to UI.

I have added my sample HTML data here. I am using a webview for showing videos. So the video links should open on the app itself using webview or any other property. And show the remaining description as normal text. I need a UI like this. How can I do this? My current UI using Xam.Plugin.HtmlLabel.

App freezes on iPad when in split view mode (multi-tasking) and change between pages

$
0
0

I have come across a very strange bug -- not sure if it in my app, Xamarin.Forms, or iOS itself.

My app switches between several pages derived from ContentPage. When I have my app and another app, for example the iOS "Pages" app on my iPad side-by-side (half screen). It seems to be related to whether the other app is in an input field before switching. Anyway, I press a Button in my app to switch to another page, and my page is kinda there, but the dark blue background want is white, plus no interaction (so, appears "frozen"). But, if move the slider to make it a 2/3 split, it immediately works.

When my app starts in 2/3 screen mode, the result is a bit comical -- the first half of my app is OK (the leftmost third of the screen), but other half refuses to allow interaction (and has white background). Weirdest thing -- one of my buttons straddles the break -- the left part works fine, the right does not.

I've not seen this on an iPad that has not updated to 13.x yet. I'm suspcious that this might be the same issue or related to White Screen after navigating to MasterDetailPage on iPAD iOS 13.2 and iOS 13.0 Broke MasterDetailPage on iPads?, so I added tags that might relate. But, here's the thing -- I'm currently using XF 4.3 (4.3.0.991221). The "solution" for the others was to update to 4.3. And, I'm not really using MasterDetailPage, and those issues don't mention SplitScreen.

I'd just like to hear if someone else has seen something like this, or has any quick suggestions before I try to create a simplified example.

Xamarin, how can i access a specific column property in sqlite so i can add the values?

$
0
0

I know how to read or show all data inserted in the database but I don't know how to query a specific data. In the my database is in Post.cs it will store date/time and get 2 datas from user.
so like this: enter image description here

Column1(ID), Column2(Date), (column3(rain1), column4(rain2).
1 12/13/2019 21 22
2 12/16/2019 21 22
3 12/16/2019 11 12
I want to do: if (rain1 && rain2) have the same date. I would like to add 2data from rain1 which is 21+11 and save the total to rain1total=32 then rain2total would be 34. I don't know where to start

here is Post.cs

namespace listtoPDF.Model
{
//Post table, user posting drainvolume
//this is the source of Binding
public class Post: INotifyPropertyChanged
{
private double? rain1Vol;
private double? rain2Vol;
//from settingspage to show up in history
string rain1lbl = Settings.Drain1LocationSettings;
string rain2lbl = Settings.Drain2LocationSettings;

//ID primary key that we will autoincrement
//These are columns ID, drain1 to 8 so 9 columns
//These are binding source for Historypage
[PrimaryKey, AutoIncrement]
public int ID { get; set; }

public static bool showLabel { get; set; }  //public class model

public string rain1Lbl
{
    get => rain1lbl;
    set => rain1lbl= Settings.Drain1LocationSettings;    
}

public string rain2Lbl
{
    get => rain2lbl;
    set => rain2lbl= Settings.Drain2LocationSettings;    
}

public string CDateTime { get; set; }

[MaxLength(3)]
public double? rain1vol
{
    get { return rain1Vol; }
    set
    {
        rain1Vol = value;
        RaisePropertyChanged("rain1vol");
    }
}
[MaxLength(3)]
public double? rain2vol
{
    get { return rain2Vol; }
    set
    {
        rain2Vol = value;
        RaisePropertyChanged("rain2vol");
    }
}
public event PropertyChangedEventHandler PropertyChanged;

void RaisePropertyChanged(string property)
{
    if (PropertyChanged != null)
    {
        PropertyChanged(this, new PropertyChangedEventArgs(property));
    }

}

}
}
here is the main that will list data entered with date

namespace listtoPDF
{
public partial class MainPage : ContentPage
{
List posts;

public MainPage()
{
    InitializeComponent();
}

protected override void OnAppearing()
{
    base.OnAppearing();
    SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation);
    conn.CreateTable<Post>();
    posts = conn.Table<Post>().ToList();
    postListView.ItemsSource = posts;     
    conn.Close();
        //right click quickwatch

}
void addbuttonHandle_Clicked(object sender, EventArgs args)
{
    Navigation.PushModalAsync(new AddRainsPage());

}

private void GetValues()
{
    //Initiate SQLite connection
    //Create table with class
    //Get the values in table
    //close the line
    SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation);
    conn.CreateTable<Post>();
    posts = conn.Table<Post>().ToList();
    conn.Close();
}       

}
Here is the page where i need query the add a certain column so i can add the data associated to it. So far it's connecting to the sqlite.

namespace listtoPDF
{
public partial class selecteddataPage : ContentPage
{
List posts;

public selecteddataPage()
{
    InitializeComponent();
}

private void GetValues()
{
    //Initiate SQLite connection
    //Create table with class
    //Get the values in table
    //close the line
    SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation);
    conn.CreateTable<Post>();
    posts = conn.Table<Post>().ToList();

    **if (Post.rain1 values have the same date )
      {
         totalrain1= then add data that have same date         
      }
     if (Post.rain2 values have the same date )
      {
         totalrain1= then add data that have same date         
      }**

    conn.Close();

}

}
}

Frequent ApplicationMessageReceived += event from MQTTnet library causes Xamarin app to crash

$
0
0

Hi!

I've been working with Xamarin the past couple days, and this is my first big side project! I'm using the MQTTnet library to connect my mobile devices to a robotic system, to move the robot and also collect data.

The issue i'm having is with the ApplicationMessageReceived event from the MQTTnet:

client.ApplicationMessageReceived += (s, e) =>{ StatusLabel.Text = Encoding.UTF8.GetString(e.ApplicationMessage.Payload) }

On the robot side it is publishing position values at about a 200ms interval over MQTT; after about 5 seconds of the app running the subscription event, it will lock and crash. This is not the case with my C# WPF and my .Net Core versions of a similar app. I can bump the interval to about 1 second interval, and it's somewhat stable, but not ideal for position readout.

Could someone give me pointers as to what might be happening, or the cause?

I have a task setup in my main program body:

        protected override void OnCreate()
        {
            base.OnCreate();
            LoadApplication(new App());

            //Task to run MQTT
        Task.Run(async () => { await App.RunAsync(); }).Wait();
        }

        static void Main(string[] args)
        {
            var app = new Program();
            global::Xamarin.Forms.Platform.Tizen.Forms.Init(app);
            Tizen.Wearable.CircularUI.Forms.Renderer.FormsCircularUI.Init();
            app.Run(args);
        }

And then in my App I have a RunAsync that does the connection and messaging, I've cut it short for readability:

        public static async Task RunAsync()
        {
                try
                {
                    // Event Handler to the ApplicationMessageRecevied event
                    client.ApplicationMessageReceived += (s, e) =>
                    {
                        StatusLabel.Text = Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
                    };

                    client.Connected += async (s, e) =>
                    {
                        await client.SubscribeAsync(new TopicFilterBuilder().WithTopic(MQTTSubTopic).Build());
                        StatusLabel.Text = "Connected";
                    };

                    // Attempt a connection to the broker
                    try
                    {
                        await client.ConnectAsync(clientOptions);
                    }
                    catch
                    {
                        PositionData.Text = "Failed";
                    }
                }
                catch
                {
                    StatusLabel.Text = "Failed";
                }

        }

At this point, I'm open to try anything :smile:

I've tried moving the Task.Run() to the OnStart() event as well, and no difference in results. My .Net Core application does have a Thread.Sleep(Timeout.Infinite) directly after the Task.Run(), but adding that to this application just prevents it from launching.

Thanks!!

xamarin forms collectionView scroll height?

$
0
0

How can we measure collectionView scroll height in xamarin forms?

Viewing all 91519 articles
Browse latest View live


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