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

Found a way to make ToolBarItems Visible/Invisible..without a custom renderer

$
0
0

So from what I've seen in the API Docs (http://iosapi.xamarin.com/?link=T:Xamarin.Forms.MenuItem/*) Toolbar items don't seem to have an IsVisible property.

I was able to accomplish this by defining a Binding for the "Icon" property and settings it to null when I don't want the toolbar item to display. So far, it has worked well.

Posting here so that anyone else looking to toggle visibility of toolbar items can try it out.


Is there a way to navigate to overflow tabs on iOS in Xamarin App Shell?

$
0
0

Currently if I navigate to a route of a tab that is in the overflow section it stops at the 'More' page. Is there a way to have it go through to the requested route?

How to make Classic Bluetooth Connectivity in xamarin.forms

$
0
0

How to make classic Bluetooth connectivity in xamarin.forms..the app search devices and connect to device.Is there any example or helping material to implement the functionality.

I mistakenly deleted ios project from solution and added again now ios simulator is not working.

$
0
0

I mistakenly deleted ios project from the solution and added again using "Add Project" now ios simulator is not working. It builds successfully but the emulator does not open. Before that's everything was fine. I am not VS Windows and connected my vs to physical Mac.

How to know if root page is reached in navigation stack

$
0
0

Hi, im developing forms app and I need to do some stuff when the root page is reached through popAsync way, debugging popAsync event I look at StackDepth property, but is for internal use only... Do you know another way?

I'm suscribed to "popped" event in my master detail code behind

VisualState Manager override Shell.Flyout appearance

$
0
0

Hi Forum,

I'm trying to override text color and background color for Shell.Flyout menu items. I'm targeting the default template from visual state manager but this is only working for 'Normal' state and not for 'Selected'. Any help?

<Style TargetType="Grid">
                <Setter Property="VisualStateManager.VisualStateGroups" TargetName="FlyoutItemLayout">
                    <VisualStateGroupList>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal">
                                <VisualState.Setters>
                                    <Setter Property="Label.TextColor" Value="Red" TargetName="FlyoutItemLabel"/>
                                </VisualState.Setters>
                            </VisualState>
                            <VisualState x:Name="Selected">
                                <VisualState.Setters>
                                    <Setter Property="BackgroundColor" Value="Blue" />                                  
                                </VisualState.Setters>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateGroupList>
                </Setter>
   </Style>

And how can i target the color for the icon. I'm using FontImageSource for Flyout.Icon

<FlyoutItem Title="Pickers">
        <FlyoutItem.Icon>
            <FontImageSource Glyph="&#xf14a;" FontFamily="FontAwesome" Color="Gray"/>
        </FlyoutItem.Icon>
        <ShellContent ContentTemplate="{DataTemplate local:PickersPage}"/>
    </FlyoutItem>

Sometimes i am getting this error.
System.ArgumentNullException: 'Value cannot be null.
Parameter name: targetObject'

What is the correct format of URI to be used in Launcher.TryOpenAsync()?

$
0
0

I am trying to start another app from my app using Xamarin.Essentials feature:

await Launcher.TryOpenAsync(new Uri("<uri-of-the-another-app>://"));

For Android, using the Pakcage Name works in a way, but the other app opens but keeps stopping several times.

For iOS, I tried using both BundleName and Application Name. But it gives the error "This app is not allowed to query for scheme ".

What is the correct format of the URI to be used here?

I have gone through various threads in this forum and stackoverflow but none of the technics working. Some posts are vague and some are confusing. But I tried different combination but so far unable to pin on a working combination.

use same browser window when using android webview callback (using pic2shop)

$
0
0

Hi, we have an Android app using the WebView control that points to a server of ours that spits out HTML. One of the buttons is a barcode scanning button, that calls pictoshop using Javascript and a redirection link like

window.location = 'pic2shop://scan?callback=https://etcetc';

When Pic2Shop scans the barcode and returns the barcode instead of it redirecting to the built-in WebView browser that initiated the call, it opens up an external web browser, thus leaving our app.

How can we get the callback to come back into our app so that our internal web view browser can show the relevant page?

Thanks,

Richard


SlideOverKit not showing on iOS

$
0
0

@MichaelRidland I'm using SlideOverKit to show a SlideDownMenu. Using the sample app as a basis, I've got it working with Android, but for iOS no menu appears. I get no errors - just no menu.

My XAML for the page is:

<?xml version="1.0" encoding="UTF-8"?>
<t:MenuContainerPage
    xmlns:t="clr-namespace:SlideOverKit;assembly=SlideOverKit"
    xmlns ="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="Project.UI.Pages.HomePage">
    <ContentPage.ToolbarItems>
        <ToolbarItem
            Order  ="Primary"
            Text   ="Settings"
            Command="{Binding ShowMainMenuCommand}" />
    </ContentPage.ToolbarItems>
    <ContentPage.Content>
    </ContentPage.Content>
</t:MenuContainerPage>

Code-behind is:

namespace Project.UI.Pages
{
    public partial class HomePage : MenuContainerPage
    {
        public HomePage ()
        {
            InitializeComponent ();
            this.SlideMenu = new MainMenuView ();

        }

        protected override void OnAppearing ()
        {
            base.OnAppearing ();
            (this.BindingContext as PageModels.HomePageModel).Page = this;
        }
    }
}

PageModel is:

namespace Project.UI.PageModels
{
    public class HomePageModel : ViewModelBase
    {

        public HomePageModel ()
        {

            this.ShowMainMenuCommand = new Command (o => this.ShowMainMenu ());

        }

        #region Properties

        public Pages.HomePage Page { get; set; }

        #region Commands

        public ICommand ShowMainMenuCommand { get; set; }

        #endregion Commands

        #endregion Properties

        #region Private Methods
        private void ShowMainMenu ()
        {
            this.Page.ShowMenu ();
        }
        #endregion Private Methods
    }
}

Update Progressbar + Label from iOS NSUrlSession Background-Download freezes UI

$
0
0

Hey guys!
I already put many hours into researching the following problem:

I have a ContentPage in my PCL-project which consists of a ProgressBar and a Label. Both should display the progress of a download running in a background task. Therefore I'm using the MessageCenter to subscribe to a channel on which I publish the current download's progress (DownloadProgressMessage).

Additionally, I have a ViewModel which holds two Properties (double DownloadProgress, string DownloadText) which are binded to the ProgressBar + Label. When I receive a new DownloadProgressMessage I update the Properties accordingly within the ViewModel so the displayed values get updated. The messaged are sent from the DidWriteData() method in my NSUrlSessionDownloadDelegate. When I run the app from VS (Debug OR Release) everything works just fine. The download starts, progressbar and label get updated. When I switch to another app and get back into mine, all values got updated accordingly. Now comes the strange part:

When I force stop the app and start it again from the homescreen of the iPad, switching to another app and coming back results in an UI-freeze. The values are stuck on the state where I left the app, but the download continues in the background. I can't debug the problem because it only appears if the app is not "connected" to VS.

Property example (using GalaSoft.MvvmLight):

private double _progressValue;
public double ProgressValue
{
    get => _progressValue;
    set { Set(ref _progressValue, value); }
}

Message subscribe in ViewModel:

MessagingCenter.Subscribe<DownloadProgressMessage>(this, "DownloadProgressMessage", message => {
    ProgressValue = message.Percentage;
    ProgressText = "downloading".Translate() + " " + message.Percentage + "% " + "percent_of".Translate() + " " + ((message.TotalBytesExpectedToWrite / 1024f) / 1024f).ToString("#0.##") + " MB";
});

DidWriteData from the NSUrlSessionDownloadDelegate:

public override void DidWriteData(
            NSUrlSession session,
            NSUrlSessionDownloadTask downloadTask,
            long bytesWritten,
            long totalBytesWritten,
            long totalBytesExpectedToWrite)
{
    // Debug.WriteLine($"{requestUri}:{percentage}%");

    var message = new DownloadProgressMessage()
    {
        BytesWritten = (long)totalBytesWritten,
        TotalBytesExpectedToWrite = (long)totalBytesExpectedToWrite,
        Percentage = totalBytesWritten * 100 / totalBytesExpectedToWrite
    };
    MessagingCenter.Send(message, "DownloadProgressMessage");

}

Does anyone have an idea why this is happening and more important, why it only happens when the app is not "connected" to VS?

Thanks in advance!

Same listview item not getting selected after pressing back

$
0
0

I have a listview which on any item selected navigates to another XAML page. When I press the back button I return back to the original listview page.

Now if I select the same list view item, it does not navigate to the intended XAML page. If I select another item in listview it navigates.

So the issue I am facing is that tapping/selecting the same item does not navigate to the intended page the second time after the back button is pressed, but any other item in the list does navigate. Also the break point is not hit in VS (onitemtapped event args), so can't debug the issue too.

Any help/suggestions on the same?.

Thanks In Advanvce!!..

Shell custom renderer how to set bottom navigation animations disable?

$
0
0

Android and ios Shell renderer how to set bottom navigation animations disable?

Can the title view background color be line gradient color in Xamarin.forms?

$
0
0

I want to make the TitleView's background color be gradient color like this:

How to do it ?

or need I use a custom control?

How to apply pagination in lisview using Xamarin forms cross platform?

$
0
0

How to apply pagination in lisview using Xamarin forms cross platform? Please help.I have searched on google but couldn't find the solution.
Thanks in advance

Xamarin Google(GoogleApiClient) SignOut

$
0
0

Hi
hear i am facing a problem to get signout feom the GoogleApiClient, the following is the code i am using currently,

Here is for the Signin

 protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                base.OnCreate(savedInstanceState);
                //Common.packageName = ApplicationContext.PackageName;
                SetContentView(Resource.Layout.activity_gmail);
                Common.clearCatchecontext = this;//ApplicationContext;

                FindViewById(Resource.Id.sign_in_button).Click += GoogleSignInButton_Click;   

                var gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
                        .RequestIdToken("5423.apps.googleusercontent.com")
                        .RequestEmail()
                        .Build();

                Common.mGoogleApiClient = new GoogleApiClient.Builder(this)
                        .EnableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
                        .AddApi(Android.Gms.Auth.Api.Auth.GOOGLE_SIGN_IN_API, gso)
                        .Build();
                Common.mGoogleApiClient.Connect();
                Common.mAuth = FirebaseAuth.Instance;

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message + ex.StackTrace + ex.InnerException);
            }
        }

once after success signin the application will call the LoadApplication(App) to redirect from pureAndroid Platoform to the crossPlatoform,
then to signOut, form the xamarin forms will call the android method as dependency injection,

Interface class and a method,

 public interface ISignOut
    {
       void SignOuts(string _value);
    }

the below is the button click,

  private async void TapRecognizserLogOut_Tapped(object sender, EventArgs e)
        {
            try
            {
                var result = await DisplayAlert("Alert!", "Do you really want to Logout the application?", "Yes", "No");
                if (result)
                {
                    if (Xamarin.Forms.Device.OS == TargetPlatform.Android)
                    {

                        DependencyService.Get<ISignOut>().SignOuts("HAI");

                    }
                }

            }
            catch (Exception ex)
            {

                System.Diagnostics.Debug.WriteLine(ex.InnerException + ex.StackTrace + ex.Message);
            }
        }

in the android implementation is below,

[assembly: Xamarin.Forms.Dependency(typeof(GmailSignInActivity))]
namespace Xaamrin_Mobile.Droid
{
    [Activity(Label = "GmailSignInActivity", Theme = "@style/MainTheme")]
    class GmailSignInActivity : AppCompatActivity, GoogleApiClient.IOnConnectionFailedListener, GoogleApiClient.IConnectionCallbacks, ISignOut
    {

     public async void SignOuts(string _value)
        {
            try
            {
                if (true)
                {
                    var _res = LoginUser._loginUser;



                    FirebaseAuth.Instance.SignOut();
                    if (!Common.mGoogleApiClient.IsConnected)
                    {
                        Common.mGoogleApiClient.Connect();
                        await Auth.GoogleSignInApi.SignOut(Common.mGoogleApiClient);//.GetAwaiter().GetResult();

                    }

                    Common.mGoogleApiClient.Disconnect();
                    Common.mGoogleApiClient.Connect();
                    var user = FirebaseAuth.Instance.CurrentUser;

                }
                           }
            catch (Exception ex)
            {
                //throw;
            }
            var intent = new Intent(Forms.Context, typeof(GmailSignInActivity));
            Forms.Context.StartActivity(intent);
            //return false;

        }
    }

}

like the above way, we are implemented, but we are not able to get signout from the GoogleAPIClient,


Error in android url scheme

$
0
0

Hi

I'm trying to make custom URL Scheme In Android

When I create a new xamarin forms app and add this code to manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.app7">
    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
    <application android:label="App7.Android">
         <activity  android:name="com.companyname.app7.MainActivity">
          <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="myapp" />
          </intent-filter>
        </activity>
     </application>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

And I call the app by clicking a link

<a href="myapp://hello-world"> Circle Here</a>

I get this error

Java.Lang.RuntimeException: 'Unable to instantiate activity ComponentInfo{com.companyname.app7/com.companyname.app7.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.companyname.app7.MainActivity" on path: DexPathList[[zip file "/data/app/com.companyname.app7-1/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.app7-1/lib/arm, /data/app/com.companyname.app7-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]'

OIDC Client Logout

$
0
0

I am following the example to authenticate a user by using this sample:
https://github.com/IdentityModel/IdentityModel.OidcClient.Samples/tree/master/XamarinForms

I have the login working, it authenticates and closes the ChromeTabBrowser and redirects back to my app screen because of the RedirectURI setting, but this sample online doesn't have an example for the Logoff functionality. How would I do the same, Logoff, and then have it close the ChromeTabBrowser and redirect back to my app, I have set the same URI I am using for login, to the PostLogoutRedirectURI property in the OidcClientOptions, but no luck.

public static OidcClientOptions SetAuthOptionsPostLogout()
{
var browser = DependencyService.Get();

        return new OidcClientOptions
        {
            Authority = GlobalSetting.Instance.AuthAuthorityURI,
            ClientId = GlobalSetting.Instance.AuthClientID,
            Scope = GlobalSetting.Instance.AuthScope,
            RedirectUri = GlobalSetting.Instance.AuthReturnURI,
            PostLogoutRedirectUri = GlobalSetting.Instance.AuthReturnURI,                               
            Browser = browser,
            ResponseMode = OidcClientOptions.AuthorizeResponseMode.Redirect
        };
    }

and my call to logout is:

public ICommand Logout => new Command(async () =>
{
try
{
LoadingMessage = "Logging Off...";
IsBusy = true;

            var options = AuthService.SetAuthOptionsPostLogout();
            Client = new OidcClient(options);
            await Client.LogoutAsync();

            //DELETE OTHER SETTINGS HERE

            IsBusy = false;
            await _Navigation.PushAsync(new Login());
        }
        catch (Exception ex)
        {
            IsBusy = false;
            await ex.TrackAndShowAlert("VM", "Logout");
        }
    });

The authentication service logs me off, but that window never closes, so in the app, the spinning "Logging Off..." is still active awaiting the call.

iOS Binding Unity as a library

$
0
0

Hi all,

I don't even know where to start :D

Since alpha 2019.3 Unity offers the feature "Unity as a Library" https://blogs.unity3d.com/2019/06/17/add-features-powered-by-unity-to-native-mobile-apps/ which I'm currently trying to integrate into one of our Xamarin Apps.
There are descriptions how to do that natively for Android and iOS which I got both working fine.
Just for reference:
https://forum.unity.com/threads/integration-unity-as-a-library-in-native-ios-app.685219/
https://forum.unity.com/threads/integration-unity-as-a-library-in-native-android-app.685240/
This is actually a really big deal so it is great working on it :D

However, I got it working fine for Xamarin Android. Now I'm trying on iOS which appears to be much more complicated.

The unity project will be exported as a native Objective-C++ framework (I think at least as there are .mm files using Objective C)
When using Sharpie to bind the framework I get a super large APIDefinitions file.
After some research I figured out that I have to define a scope to the Headers of the Framework, then the APIDefinitions are in fact much smaller and only reference the header files.

Now to my (current) problem:

If I open the ApiDefinitions then there is an interface UnityFramewok which comes from the UnityFramework.h file.
But this header holds a reference to a class UnityView which is not part of the headers. It is within the framework( at least it is within the Library project in Xcode so I assume it is bundled into the framework.)
I copied the .framework into the bindings Native References but I can't see any actual change happening when I do that.
The UnityView can not be found within the interface and I also can't import it from the library because the native reference is not available.

So how can I reference to a class of the framework from within an interface that is defined in the ApiDefinitions?

Thank you already!

Xamarin.Forms Shell - when a ContentPage is destroyed?

$
0
0

Am having a Xamarin.Forms Shell application. On the main page I have a list of some objects and on a button click I navigate to a detail page (DetailPage class) like this:

Shell.Current.GoToAsync(url_to_detail_page?id=X);

New instance of DetailPage is created and properly displays object X.

I navigate back to main page.

I click the button to navigate again to a detail page (another object with another ID):
Shell.Current.GoToAsync(url_to_detail_page?id=Y);

New instance of Detailpage is created and properly displays object Y.

But at this moment both DetailPage instances (X and Y) obviously still exists. The DetailPage subscribes to an MessagingCenter event and once this message is sent it is triggered on both X and Y instances of the page.

**Is this normal that the ContentPage is not destoyed when navigating back from it? **

Handling the MessagingCenter event takes some time and I don't want to run it multiple times... I can handle that somehow but it would be a workaround. I would prefer the DetailPage to be destroyed as it is no longer needed.

thansk

Jiri

Any way to detect when user closed browser opened with Browser.OpenAsync?

$
0
0

Using the following to open an in-app browser:
await Browser.OpenAsync("https://visualstudio.microsoft.com/", BrowserLaunchMode.SystemPreferred);

Is there a way to detect when user press X or Done and comes back to the app?

Viewing all 79144 articles
Browse latest View live


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