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

Local XAML namespace in Shared project

$
0
0

Hello,

I tried to declare a local XAML namespace in my pages in a Shared Xamarin.Forms project like this :

     xmlns:local="clr-namespace:MyProject.Example;assembly=MyProject.Example"

It doesn't work, and that is obvious because a Shared project isn't built but its content is copied in other projects with different assemblies (MyProject.Example.iOS, MyProject.Example.Android, ...).

How can I achieve this ?

Thank you !


Why does my data bind to my listview, but not Fontsize or TextColor?

$
0
0

I set a FontSize property in my viewmodel, then I bind it in my Style, but the Fontsize doesn't trickle down to my listview label. I've also tried binding directly on the listview label, but this doesn't work either. If I hard code my fontsize into the style, it works but I need dynamic fontsize, especially in UWP.

Also, please notice that my data binds properly inside the listview but my TextColor won't bind either. Anything you can think of would be greatly appreciated.

//My Style
      <Style x:Key="settingsLabelStyle2" TargetType="Label" BasedOn="{StaticResource settingsLabelStyle}">
                    <Setter Property="HorizontalOptions" Value="Start" />
                    <Setter Property="VerticalTextAlignment" Value="Center" />
                    <Setter Property="FontSize" Value="{Binding ScoreFontSize}" />
                </Style>


    //Part of my listview
      <DataTemplate>
                                <ViewCell>
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="*" />
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="7*" />
                                            <ColumnDefinition Width="4*" />
                                            <ColumnDefinition Width="*" />
                                        </Grid.ColumnDefinitions>

                                    <Label Grid.Column="0" Text="{Binding GameDate}"  Style="{DynamicResource DynamicSettingsLabelStyle2}" />
                                            <Label Grid.Column="1"  Text="{Binding PlayerName}"  Style="{DynamicResource DynamicSettingsLabelStyle2}" />
                                            <Label Grid.Column="2"  Text="{Binding Score}"  Style="{DynamicResource DynamicSettingsLabelStyle2}" />
                                        </Grid>
                                    </ViewCell>
                                </DataTemplate>


    //My Fontsize property


            private double scoreFontSize = 20;
            public double ScoreFontSize
            {
                get { return scoreFontSize; }
                set
                {
                    SetProperty(ref scoreFontSize, value);
                    OnPropertyChanged();
                }
            }

Issue when Create new Xaml forms on F# project

$
0
0

Hello All,

I have some issue when create new Xaml forms on F# project, I use Visual Studio for Mac version 7.4.2 (Build 12).

The issue is when I create new Xaml project the namespace of the Xaml and the code behind is not correctly updated and give result like this code:

On the Code behind:

namespace ${SafeUserDefinedProjectName}

open Xamarin.Forms
open Xamarin.Forms.Xaml

type EwsPage() =
    inherit ContentPage()
    let _ = base.LoadFromXaml(typeof<EwsPage>)

The namespace not correct and still give ${SafeUserDefinedProjectName} as result, please help if someone have solution for this case.

Thanks,

Xamarin forms Scrollview Scrolled finished/ending how to know

$
0
0

Hey.

I am trying to find a way, to know when a scrollview is not scolling anymore, so after the scoll is stopped, i can call ScrollView.ScrollToAsync, to position the element, that is closet to the center of my View content. But before i can make the last small position of my elements, i have to know that, _scrolledEventArgs.ScrollX is not changing anymore.

Hope some one can help.

how to create class like MainPage.ButtonFacebook_Clicked.xaml.cs in visual studio

$
0
0

How to create class like MainPage.ButtonFacebook_Clicked.xaml.cs in visual studio.Which item i have to choose to create such a class.Usually we have MainPage.xaml.cs which is generated automatically.Please help me. :(

which folder is images on Wp81 and UWP?

$
0
0

Xamarin documentation says that I should add images directly under the project without any sub folder if I am referring to from XF project but I saw in video on channel9, they were adding images under assets folder? Is there anyway to use subfolders for wp81 and uwp?

How to implement XAML Css

$
0
0

hello, guys, can you explain how to implement XAML style with CSS and give me any references to ebook or any git project for exercise

How to download a file in Xamarin Forms and store it in the device storage ?


Custom GridView with Bindable DataSource and Template

$
0
0

Hello,

i made a CustomGrid with a BindableProperty ItemsSourceProperty as seen Below.

class CustomGrid : Grid { public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create( "ItemsSource", typeof(ObservableCollection<DeviceParameterItem>), typeof(CustomGrid), propertyChanged: (bindable, oldvalue, newvalue) => { newvalue = ItemsSourceProperty; });
I am able to bind the ItemsSource in my ViewModel and it's creating my Grid dynamically in respect to the DataSource.

Now, i want the Data to update without Building the whole Grid new, because i have data in the grid which changes every few milliseconds.

Can you pls give me a hint on how to do this?

Deployment Error when i using Push Notification.

$
0
0

Hi,
Am New to Xmarin forms,
Am trying to Implement Push Notification to my project, for that am using App Center and Google Firebase by watching some videos. Implemented without any Build Error. But while Deploying in debug mode am getting following Error.

**Android application is debugging.
The application could not be started. Ensure that the application has been installed to the target device and has a launchable activity (MainLauncher = true).

Additionally, check Build->Configuration Manager to ensure this project is set to Deploy for this configuration.**

after spending 3 hours i came to know this is the problem because of i put thease lines in AndroidManifest.xml

**<permission android:protectionLevel="signature" android:name="${applicationId}.permission.C2D_MESSAGE"
<uses-permission android:name=""

after commenting the above line deployment working fine. but push notification not working.
pls help me

thank you

The "AdjustJavacVersionArguments" task failed unexpectedly

$
0
0

When I try build my Xamarin.Forms Android solution in Visual Studio 2017, I got error message:

everity Code Description Project File Line Suppression State
Error The "AdjustJavacVersionArguments" task failed unexpectedly.
System.NullReferenceException: Object reference not set to an instance of an object.
at Xamarin.Android.Tasks.AdjustJavacVersionArguments.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() XamarinApp2.Android

What could be the cause of this error?

Hide and show listview items based on a string value.

$
0
0

I have a listview like the following picture. There is a more icon(in blue color) and switch on the right side of each list item.

I have a string variable called type, if "type" value is "switch", I need to hide the more icon from the list and show switch icon only and if the "type" value is "more" hide the switch from the list and show more icon only.
The more and switch are inside listview like below:

<ListView>
      <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <ViewCell.View>
                                <StackLayout>
                                        //Items like profile image name 
                                         <Image   //more icon     />
                                          <Switch/>
                                 </StackLayout>
                            </ViewCell.View>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
          </ListView>

Thanks in advance

Logout Display alert xamarin.forms

$
0
0

I've been trying to allow a user to confirm logout by using DisplayAlert. If they click "No" it should remain in their profile page else they should be redirected back to the login page. I haven't managed to get this done, if I click Yes or No, both options remain in the profile page
Below is my code:
public async void LogoutBtn(object sender, EventArgs e)
{
var answer = await DisplayAlert("Exit", "Do you wan't to exit the App?", "Yes", "No");
if(answer.Equals("Yes"))
{
Settings.FirstName = string.Empty;
Settings.LastName = string.Empty;
Settings.Email = string.Empty;
await Navigation.PushAsync(new MainPage());
}
else
{
App.Current.MainPage = new Profile();

                }

            }

OnElementChanged triggered in a custom renderer for all elements under iOS

$
0
0

Hi!,
of course my first posting is a question. :)

I am developing a Xamarin Forms Application for iOS and Android. One part of it shows a list with pictures, which are downloaded from a server. In the PCL we bind a List to the ListView and use a customrenderer for the picture view. So far all was well, until the last update of our nuget packages, which also included Forms updates.
The Android App works as before, but the iOS Version shows now a different runtime behaviour.
In OnAppearing of the page we convert the received list and add the items to the bound List:
ObservableCollection _listData = new ObservableCollection();

and while adding the elements i already see a difference between Android and iOS:

Android: Alle Elements are added to the list and afterwards the OnElementChanged of the custom renderer is triggered. Additionally only the visible "Customrenderers" are called. Which results in an expected behaviour.

iOS: right after adding an Element to the list, OnElementChanged of the custom renderer is triggered. Also it is called for all elements. Additionalyl I see for the first/second none visible element e.OldElement passed as parameter, and from there on for each new element OnElementChanged triggered one more time. It seems, for me, that the list is shifting elements and triggering every time the event. This results in a lot of calls and additional all Pictures are downloaded at the same time. Funny fact: the downloads are now also finished at the same time. Because the app downloads more Pictures as needed on start up, the user has to wait some time.

Now the Question: How could I get the same behaviour in iOS like Android? Or the other way round, what causes the difference?

Thanks
Wolfgang

getting error "System.UriFormatException:Timeout exceeded getting exception details"


Not taking back to app from google auth page

Closing Xamarin.Forms Page Causes App to Crash

$
0
0

Hi

While writing this, I got it working, but posting anyway in case it helps someone else

I am having issues closing a page on Xamarin.Forms running on Android. My app is monolithic - the Android activity launches a Xamarin.forms page based on the content of an Android intent. For this reason I have the decoration:

LaunchMode = LaunchMode.SingleTask, ExcludeFromRecents = true, NoHistory = true

On my Android activity - When back or home is pressed, there is nothing in resents. If the activity is already active and another intent is bound for my app, no new activity is launched (Launchmode.SingleTask), rather I simply switch the active page (while maintaining no history).

This intent comes via a tap, bluetooth characteristic change or via NFC. One of my pages is simply a popup on an NFC intent that initiates a connection to a BLE device.

Onto the Issue

In one of my pages I have a simple 'Close' button, the page is launched via an intent as above, currently (for debug) the close is wired to the codebehind (it will end up being done from the viewmodel off a timer). I have thus far tried three methods to close the page all of which result in a crash:

1) Close();
2) await Navigation.PopModalAsync();
3) Through the DependancyService using an interface that calls: activity.FinishAffinity(); (also tried just Finish() and FinishActivity()

For 1) and 2), I get exceptions thus

1) exception = {System.InvalidCastException: Specified cast is not valid. at ProteusPatientApp.Views.ConnectionStatusPage.Close () [0x00001] in ConnectionStatusPage.xaml.cs:32

2) Message = "Index was out of range. Must be non-negative and less than the size of the collection.\nParameter nam…"

I believe that both of the above failed due to the monolithic, no history, no navigation stack nature of my app.

For three, one needed to get the activity, but the getter mechanism 'Xamarin.Forms.Forms.Context' is obsoleted. I tried 'Android.App.Application.Context' but this resulted in an 'InvalidCastException'.

The solution was to implement the IActivityLifecycleCallbacks interface. There are two ways of doing this - using James Montemagno's Plugin.CurrentActivity which implements the IActivityLifecycleCallbacks in a file MainApplication.cs, or to manually implement the interface. Since implementing the interface is easy, I went for the manual method. The hints for this came from: https://stackoverflow.com/questions/47353986/xamarin-forms-forms-context-is-obsolete and you can simply paste the code from this into a new file MainApplication.cs.

I moved the decoration for [Application] from the Manifest into the MainApplication.cs thus:

 [Application(Label="ProteusPatientApp.Android",Icon="@drawable/spacelabs_logo",  Theme="@android:style/Theme.Translucent.NoTitleBar")]
 public partial class MainApplication : Application, Application.IActivityLifecycleCallbacks
........

I also had to remove the code:

[assembly: Application(Debuggable = true)]

From my application as otherwise the thing threw a load of Java errors during compilation - I never for to the bottom of this. Anyway, I can now Close the current Activity (or a Popup window implemented using Rg.Plugins.Popup either with button press or programatically.

Following on from that you just need an interface in your UI code 'ICloseApplication.cs':

    namespace ProteusPatientApp.Interfaces
    {
        public interface ICloseApplication
        {
            void CloseApplication();

        }
    }

And an implementation for it in your Android code 'CloseApplication.cs':

[assembly: Xamarin.Forms.Dependency(typeof(ApplicationCloser))]
namespace ProteusPatientApp.Droid
{
    public class ApplicationCloser : ICloseApplication
    {
        public void CloseApplication()
        {

            var activity = (Activity)MainApplication.ActivityContext;
            activity.FinishAffinity();
        }
    }
}

On Android my service does the work, and calling activity.FinnishAffinity() only closes the activities - the service sits there waiting to do work. Things are different on iOS as it has no concept of services or (for non Voip apps), boot start apps. If you do want to close the app in iOS, you can implement the close interface thus. NB: Apparently this is not recommended - iOS likes to maintain the lifecycle of apps by its-self, and going DIY can cause you issues with store approvals - so says the internet. I have not done the iOS bit for my app as yet.

    [assembly: Xamarin.Forms.Dependency(typeof(ApplicationCloser))]
    namespace ProteusPatientApp.iOS
    {
        public class ApplicationCloser : ICloseApplication
        {
            public void CloseApplication()
            {
            Thread.CurrentThread.Abort();
            }
        }
    }

Nigel

Two-way binding on Native Control causes severe crash— am I doing it right?

$
0
0

My Mac, Xcode and Visual Studio for Mac are all completely up to date as of writing.

I create a new forms app from the template.

On AboutPage.xaml, I add the iOS namespace by adding xmlns:ios="clr-namespace:UIKit;assembly=Xamarin.iOS;targetPlatform=iOS" to the ContentPage node.

I then add a ios:UITextField Text="{Binding Test, Mode=TwoWay}" node about the AppName label.

In AboutViewModel.cs, I add a test property, like so:

private string test = String.Empty;

public string Test

{

get { return test; }

set { SetProperty(ref test, value); }

}


When I play this application in the Simulator (iPhone X iOS 11.3), when I enter text into the UITextField on the about page, it horribly crashes.

I can’t catch the exception, this seems to be a really low level crash.

Have I done this wrong?


Application.Current.Properties Can not persist in Android ,Using XF 1.42

$
0
0

It work fine on iOS but when android os restrart ,the properties is empty ,even I use
await Application.Current.SavePropertiesAsync();
after set the value

getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), KnownFolders etc

$
0
0

getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) and KnownFolders (Android, UWP)

Im using Xamarin.Forms, but I need to use the above platform specific features(and others) to get some info. I cant just chuck them into my .NETstandard PCL, that seems clear. Do they need to go in the platform specific projects? Um, How?

Viewing all 58056 articles
Browse latest View live


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