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

ListView.ItemTapped w/ViewCell.ContextActions always sending first item in list on Android: new bug?

$
0
0

So I noticed some developers were experiencing a bug where ListView.ItemTapped would not fire at all if the ViewCell in the ListView's ItemTemplate had ContextActions defined. This is on Android.

I'm actually getting ItemTapped events, but ItemTappedEventArgs.Item is always the first item in the list, not the item that was tapped. Weird thing about it is that when I set a breakpoint in the event handler and look at ItemTappedEventArgs.Item in the watch window, I see the tapped item. But when I do var selectedItem = (ItemType)e.Item; then selectedItem is THEN the first item. Oh, and evaluating ItemTappedEventArgs.Item in the debugger watch window produces this error in the output window, but I still see data in the watch window:

System.ArgumentException: The field 'k__BackingField' is not valid for this type.
at Mono.Debugger.Soft.ObjectMirror.GetValues(IList`1 fields) in E:\A_work\785\s\external\debugger-libs\Mono.Debugger.Soft\Mono.Debugger.Soft\ObjectMirror.cs:line 93
at Mono.Debugger.Soft.ObjectMirror.GetValue(FieldInfoMirror field) in E:\A_work\785\s\external\debugger-libs\Mono.Debugger.Soft\Mono.Debugger.Soft\ObjectMirror.cs:line 74
at Mono.Debugging.Soft.FieldValueReference.get_Value() in E:\A_work\785\s\external\debugger-libs\Mono.Debugging.Soft\FieldValueReference.cs:line 129
at Mono.Debugging.Evaluation.ValueReference.GetValue(EvaluationContext ctx) in E:\A_work\785\s\external\debugger-libs\Mono.Debugging\Mono.Debugging.Evaluation\ValueReference.cs:line 206
at Mono.Debugging.Evaluation.ValueReference.OnCreateObjectValue(EvaluationOptions options) in E:\A_work\785\s\external\debugger-libs\Mono.Debugging\Mono.Debugging.Evaluation\ValueReference.cs:line 135
at Mono.Debugging.Evaluation.ValueReference.CreateObjectValue(EvaluationOptions options) in E:\A_work\785\s\external\debugger-libs\Mono.Debugging\Mono.Debugging.Evaluation\ValueReference.cs:line 106


How to write logs to file?

$
0
0

I am building my project using .NET Standard. Is there any way to write logs to file in Xamarin?

Binding control details from ViewModel is taking long time for ListView in xamarin.forms

$
0
0

I am working on xamarin.forms application, there I have a list view with 11 Stack layouts and different designs for each stackLayout.

Here, all the colors and visibilities for all controls in the stack layout are binded from the viewModel.

The problem is while loading the application the listview is loading for view but there it is taking about to 10-30 sec of time to bind the design for the listview from the ViewModel.

Is there any way to make the design to load quickly to view.

Facebook and Google login in Xamarin.Form

$
0
0

Hello, my name is Daniel, I'm from Uruguay and I'm currently working on my final year project. It is a Cross-Platform application for Android and iOS. At this moment we are in an advanced stage of development, in which we are trying to incorporate advanced functionalities with my partner Diego. One of them is to be able to enter the app by logging in via Google or Facebook. For this we find a lot of information in google and in the forum but it is not adapted to the project or it is old. What we find always applies to the android project and not to the pcl. We want from our xaml page to be able to enter as google or facebook users.
We are currently working on .Net Standard and Android SDK v8.1
Could someone help us or provide information?
Thank you.

Striped listview - performance

$
0
0

Hello,
I created a ListView with alternating row colors. There are many tutorials over the Internet how to do that, i.e. here:

https://forums.xamarin.com/discussion/27896/listview-alternating-row-background-colors

Unfortunately, the performance is quite bad when the number of items grows. For normal Listview, we can use caching strategy "Recycle Element" to have a nice performance. Unfortunately, it does not work for striped Listviews because cells are not identical. So how to have a nice performance in striped ListViews?

Searchbar in TitleView does not fit

$
0
0

Hello,

I have been struggling with NavigationPage.TitleView new feature (XF >3.2) and what seems to be a bug or a lack of development from the xamarin team's part.
I am trying to integrate a searchbar in the navigation bar. As you can see on the following picture I can't get rid of useless gaps nearby the back button Moreover the right of the searchbar finishes outside of the screen when I use FillAndExpand. I think that both of these problems are related.

My code :
<NavigationPage.TitleView> <StackLayout Orientation="Horizontal" Margin="0" Padding="0" HorizontalOptions="FillAndExpand" BackgroundColor="Red" Spacing="0"> <SearchBar Margin="0" HorizontalOptions="StartAndExpand" Placeholder="{Binding SearchPlaceHolder}" TextColor="{StaticResource OddColor}" PlaceholderColor="{StaticResource SecondIconColor}" BackgroundColor="Transparent" Text="{Binding Keyword}" FontSize="16" CancelButtonColor="{StaticResource OddColor}" SearchCommand="{Binding SearchCommand}"> </SearchBar> </StackLayout> </NavigationPage.TitleView>

Is there any workaround for this? It seems to me that XF calculates the width of the screen to adjust the searchbar width but does not take into account the backbutton's width. I would prefer not to set the width of the searchbar by myself.
Regards,

Button with Image and Text

$
0
0

Hi,
I have a Button with an Image inside, but my users think that a picture with text would be better. The problem is, when the resolution is not too big, text and image takes too much place. A better solution is, when the display/resolution is big enough, show the picture with text otherwise the image only. I took a look into the VisualStateManager stuff, but do not know how I to trigger the different states by changing the resolution. This XAML style I place into the button style:

               <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="ShowTextStates">
                        <VisualState x:Name="ShowText">
                            <VisualState.Setters>
                                <Setter Property="Text" Value="Test test test..." />
                            </VisualState.Setters>
                        </VisualState>
                        <VisualState x:Name="HideText">
                            <VisualState.Setters>
                                <Setter Property="Text" Value="" />
                            </VisualState.Setters>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>

How can I solve this problem? Any suggestions? Thank you!

Visual Designer for Xamarin Forms - Blend or an alternative?

$
0
0

Hi.

I was looking for a Visual designer for Xamarin forms.

I tried loading up Blend but there was no Visual Designer for the XAML just I could just see that XAML code.
This is unlike a UWP app where this seems possible.

Are there any other options. I am looking for an easy way to prototype for a designer type person to use.

Or is the only way to do it in Visual Studio and manually do the XAML.

If this is the case are there any other plans that Microsoft has to enhance Blend to make this work.

Thanks,

Ward.


How could I add an external database to my project with sqlite?

is any Drag and Drop tools available for ui in xamarin forms similar to WPF?

$
0
0

i am using visual studio 2017,for xamarin forms they have provided the drag and drop option to design in xaml but in preview of the design i am not able to edit the ui similar as in WPF

Can't catch exceptions from HttpWebRequest after Xamarin update

$
0
0

Hi,

I recently updated everything in my Visual Studio Mac installation. I still use Xamarin Forms 3.1 though.

After this update, I have got a lot of crashes from Android users (I haven't released the iOS version yet) and it seems to be related to HttpWebRequest. I use it in the following way:

        WebRequest req = HttpWebRequest.CreateDefault(new Uri(url));
        req.Timeout = TimeoutMilis;
        ...
        using (Stream dataStream = req.GetRequestStream())
        {
            dataStream.Write(data, 0, data.Length);
        }

I have a try catch around it, but it seems like these errors are not caught. The stack traces I get are not very helpful either:

        android.runtime.JavaProxyThrowable: System.AggregateException: A Tasks exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. ---> System.Net.WebException: The request was aborted: The request was canceled. 

        caused.AggregateException(s)
        System.Net.HttpWebRequest.<MyGetResponseAsync>d__243.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        --- End of inner exception stack trace ---
        ---> (Inner Exception #0) System.Net.WebException: The request was aborted: The request was canceled.
        System.Net.HttpWebRequest.<MyGetResponseAsync>d__243.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0

Another similar crash:

         android.runtime.JavaProxyThrowable: System.AggregateException: A Tasks exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. ---> System.ObjectDisposedException: Cannot access a disposed object. 

        caused.AggregateException(s)
        Object name: 'System.Net.Sockets.Socket'.
        System.Net.Sockets.Socket.ThrowIfDisposedAndClosed()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.Sockets.SocketTaskExtensions.<>c.<ConnectAsync>b__2_1(IAsyncResult asyncResult)<1430f9cebba746309b69090b6cda9ce8>:0
        System.Threading.Tasks.TaskFactory<TResult>.FromAsyncCoreLogic(IAsyncResult iar, Func<T, TResult> endFunction, Action<T> endAction, Task<TResult> promise, bool requiresSynchronization)<e7c4dd6cd0ad467d9712102a6791959b>:0
        System.Net.WebConnection.<Connect>d__16.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.WebConnection.<InitConnection>d__19.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.WebOperation.<Run>d__57.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.WebCompletionSource<T>.<WaitForCompletion>d__15.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.WebOperation.<GetRequestStream>d__49.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        --- End of inner exception stack trace ---
        ---> (Inner Exception #0) System.ObjectDisposedException: Cannot access a disposed object.
        Object name: 'System.Net.Sockets.Socket'.
        System.Net.Sockets.Socket.ThrowIfDisposedAndClosed()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.Sockets.SocketTaskExtensions.<>c.<ConnectAsync>b__2_1(IAsyncResult asyncResult)<1430f9cebba746309b69090b6cda9ce8>:0
        System.Threading.Tasks.TaskFactory<TResult>.FromAsyncCoreLogic(IAsyncResult iar, Func<T, TResult> endFunction, Action<T> endAction, Task<TResult> promise, bool requiresSynchronization)<e7c4dd6cd0ad467d9712102a6791959b>:0
        System.Net.WebConnection.<Connect>d__16.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.WebConnection.<InitConnection>d__19.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.WebOperation.<Run>d__57.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.WebCompletionSource<T>.<WaitForCompletion>d__15.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0
        System.Net.WebOperation.<GetRequestStream>d__49.MoveNext()<1430f9cebba746309b69090b6cda9ce8>:0

Has anyone had a similar problem?

Position of button in Navigationbar

$
0
0

Hi I'm trying to add a button in the navigation bar but for some reason it gets a very strange position, does someone why it positioned like this and how to solve it, I want, my button to be all the way to the right.

My code looks like this:

<ToolbarItem Name="MapSeek" Icon="MoP_ico4.png" Text="" Order="Primary" Priority="0" />

main language not available as resx file, load second language and not the default language

$
0
0

Hi,

i use multilingual app toolkit in my app and everythin works fine so far,
but on android if i add following language order to the OS

1-spain (no resx file available)
2-german (resx file available)
3-english (resx file availeble and default)

the app is always loaded in english not german.

on iOS with the same order, the app is always in german

how do I get the same behavior on android?

Processing time value from JSON string

$
0
0

Hi

I need help processing a time value I've retrieved from MySQL through a web service. I can have it as a string but when I tried processing it as a DateTime and TimeSpan I've had no luck.

PHP web service code:
$response = array();

$sql = "SELECT startTime, endTime FROM doctor_work_days WHERE doctorNo=".$doctorNo." AND dayOfWeek='".$selectedDay."' ORDER BY startTime ASC";
$result = $connection->query($sql);

if ($result->num_rows > 0) {

    while($row = mysqli_fetch_array($result)){

            $data['startTime'] = $row['startTime'];
            $data['endTime'] = $row['endTime'];
            $fetch_data[] = $data;
    }

    $response['doctorWorkList'] = $fetch_data;
    $response['success'] = 1;

}
else
{
$response['success'] = 0;
}

echo json_encode($response);

Result:
{"doctorWorkList":[{"startTime":"10:00:00","endTime":"16:00:00"},{"startTime":"18:00:00","endTime":"22:00:00"}],"success":1}

Objects I'm processing it with:
public class DoctorWork
{
public string startTime { get; set; }

    public string endTime { get; set; }

}

public class DoctorWorkList
{
    public ObservableCollection<DoctorWork> doctorWorkList { get; set; }

    public string success { get; set; }
}

Code getting the json string:

result = response.Content.ReadAsStringAsync().Result;

            doctorWorkTime = JsonConvert.DeserializeObject<DoctorWorkList>(result);

            if (doctorWorkTime.success == "1")
            {

                await this.DisplayAlert("hey", result.ToString() +" - "+ doctorWorkTime.doctorWorkList[0].startTime +" - "+ doctorWorkTime.doctorWorkList[1].endTime, "OK");

            }
            else if (doctorWorkTime.success == "0")
            {

                await this.DisplayAlert("Sorry", "No doctors are available on this date. Please select another.", "OK");

            }

I can display the values and they are correct but I can't use them. Sorry if this is a stupid issue.

Thanks.

How to integrate apply pay and Google pay in Xamarin Forms

$
0
0

Is there any way to implement apply pay in xamarin forms application. I know it can be done by dependency injection but if anyone has code then please share...


Global Exception Handling

$
0
0

Hi Everyone. I'm in my final submission of my Xamarin forms App. I want to handle Exceptions Globally in my Project. I tried this https://peterno.wordpress.com/2015/04/15/unhandled-exception-handling-in-ios-and-android-with-xamarin/ but it's not working.

    AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
        TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;  

The above methods are not invoking when any exception raised. Any kind of help will be appreciated.

Formatting a string in Label

$
0
0

Hey there. Im using crossplatform Xamarin.Forms

Is there an easy way of formatting a string looking like this:

string uText = "This **is** *just* a __small test__ yup";

Where "is" is bold, "just" is italic and "small test" is underlined?

Because the idea I have is a long way to go.

I would do an

                FormattedString formatMyString(string aString)
                {
                    FormattedString formattedString = new FormattedString();
                }

methode. I would search for an * or _ then add an new Span to formattedString from char 1 to * or _ to which I dont give any FontAttributes.
Then I would look for the next * or _ and would give the text between those characters an FontAttribute and so on.
Is there an easier way to do this?

If it matters: Im receiving an webapi string where I could get such a string.

How to show a text from html content in Xamarin.Forms.Platform.WPF?

$
0
0

I am working to show a label. We are receiving the HTML content, we have to get a text from HTML content and need to show as a label. I am unable to get the text from HTML content. If anyone has a solution please let me know. Thanks in advance.

uwp scaling issue with strokecontainer vs. image

$
0
0

I've been having the most maddening scaling issue, I'm hoping someone else has seen this one before.

I have a very basic image/inkCanvas on my page. Here is the xaml.

Open Bracket Image x:Name="image" Margin="0" Grid.Row="1"/ Close Bracket
Open Bracket InkCanvas x:Name="inkCanvas" Margin="0" Grid.Row="1"/ Close Bracket

On the back side the code that saves the images looks like this:

internal async Task<byte[]> GetImageAsBytes()
        {            
            var device = CanvasDevice.GetSharedDevice();
            using (var canvasBitmap = (!string.IsNullOrWhiteSpace(BackgroundImagePath) && File.Exists(backgroundImagePath)) ?
                await CanvasBitmap.LoadAsync(device, BackgroundImagePath) : null)
            {
                var renderTarget = new CanvasRenderTarget(device, (int)inkCanvas.ActualWidth, (int)inkCanvas.ActualHeight, 96);
                using (var session = renderTarget.CreateDrawingSession())
                {
                    session.Clear(Colors.White);
                    if (canvasBitmap != null)
                    {
                        session.DrawImage(canvasBitmap);
                    }
                    session.DrawInk(inkCanvas.InkPresenter.StrokeContainer.GetStrokes());
                }
                var stream = new InMemoryRandomAccessStream();
                await renderTarget.SaveAsync(stream, CanvasBitmapFileFormat.Png);
                return await ConvertStreamToBytes(stream);
            }    
        }

On iOS and Android, all is well. When I emulate a UWP device on my laptop using visual studio's emulator, all is well. But when I use a surface (Home or Pro, both show the issue) I get a scaling issue.

In particular, the issue is that the strokes are shrunk down and stored in the upper left of the image. So if I take a picture of an object and draw a box around it on the screen, once I've saved the image the picture ends up in the upper left corner of the image, no longer around the object.

It feels like the problem has to be with the surface having a higher resolution camera, or something similar, but I don't get why the strokes would not still be synced with the size of the canvas. Has anyone got an idea what might be going on here, and how I might solve it?

-Thanks,
Walter Langendorf

Async void behave different on uwp/android

$
0
0

Hi ,

I have this method that I call to bring me the index of an element inside picker .
this works fine on UWP but on android , sometimes it returns the value and sometimes not ..is this is because of "async" couldn't undersatnd the problem here , since , it works 1/5 times on android and just run fine on uwp?

` private async void Initlocation()
{

        DataService d = new DataService();
        var locationss = await d.GetLocatiosn();

        for (int x = 0; x < locationss.Locations.Count(); x++)
        {
            if (locationss.Locations[x].LocationID == Settings.DefaultLocation)
            {
                PickMe.SelectedIndex = x;
                break;

            }
        }

    }`
Viewing all 89864 articles
Browse latest View live


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