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

Disposing of a ContentView that is included in a ContentPage

$
0
0

Hi

My app has several 'ContentPages' which incorporate several 'ContentViews'. I have included UI elements (such as a status bar) into a ContentView which I can then display from any ContentPage.

My ContentViews have their own ViewModels, and in the case of the status bar, it subscribes to ConnectionStateChanged and DatabaseChanged events from my back end code, and needs to neatly unsubscribe when the Page that incorporates the view disappears.

Is there a way to neatly dispose of the viewmodel associated with a ContentView - I note that View's dont implement dispose, and that, unlike a ContentPage, there is no OnDissapearing event that I can manually tie up.

At the moment, in the onDissappearing override for the ContentPage that calls up my ContentViews, I am calling each of the Dispose methods I have added to the codebehind for my contentViews using the x:Name="xyz" tag from the Xaml thus:

 protected override void OnDisappearing()
        {
            CompletedPatientEventsListCtrl.Dispose();
            BleNfcConnectionControl.Dispose();
            PatientEventsAwaitingCompletionCtrl.Dispose();
            ProteusConnectionStatusCtrl.Dispose();
            base.OnDisappearing();
        }

My question is - is there a better way?

Nigel


Creating a ViewRenderer (Custom view) programatically

$
0
0

I have a ViewRenderer implemented and I want to create from an (Android) platform an instance of this ViewRenderer (Let's call it HybridWebview) from code.

So far, all easy
hybridWebview = new ProjectPCL.HybridWebview ();

The object is created but the native "OnElementChangedOnElementChanged" is never fired, I guess because I do not add it to a form.

I can not add it to a form/activity because I do not have it, I want to create it in a service: It is a webview and I need to process Javascript.

This works without problems, I already have applications that do it, what I had never tried is that Webview was a ViewRenderer.

So the question is: How can I force that view to be created and therefore rendered without having a form?

Thank you.

How to change the listview scrollbar color in xamarin.forms using Custom Renderer?

$
0
0

I am able to change the color in Android. but in Ios i'm able to change only the black, white and default color using the UIScrollViewIndicatorStyle but unable to set custom Color, how to set custom color ?

Hardware Back Button

$
0
0

I've got an app which displays a login page modally when it detects that the user has not logged in. However, the user can still dismiss the login page using the hardware back button, thus returning to the app without valid credentials which shouldn't normally happen. It's not designed to have the user attempting to do things without permission so this behaviour can be confusing. Can I somehow disable the back button on the login page?

Unfocused of Entry Control not working properly on few Android devices

$
0
0

Hi,

I have two entry controls in my Xamarin forms. I have registered to Unfocused event of both entry control with respective target methods. The Xamarin forms version I am using is "3.6.0.344457". Here, when I Unfocus from first entry control and set focus of second entry control, the Unfocus event of both the entry controls i.e. first and second entry control get called.Whereas, it should only call UnFocus of first entry control. Also, when I erase whole content from second entry control using backspace key of softkeypad, UnFocus event of second entry control gets called. Whereas the Focus is still on "Second Entry Control". This happens only on certain Android phones like Huawei, Google Pixel with Android version 8.0.

It works perfectly fine on samsung S8 and S10 phones having Android version 9.0.0.

So, Can anyone guide me whether it is OS specific issue and why it is working fine with some devices.

Waiting for the answer.

Thanks in Advance,
Muffadal

How to resolve Could not load file or assembly 'Xamarin.Forms.Core, Version=2.0.0.0

$
0
0

Since updating my PCLs to use .Net Standard 2, my Android build is reporting the following. Can anybody suggest how to resolve this please? I am using VS 2017 Community v15.9.13 . My iOS and UWP builds work fine.

Using "RegisterAssembly" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Task "RegisterAssembly" (TaskId:631)
  Task Parameter:Assemblies=G:\tfs\myapp\myapp\AndroidForForms\AndroidForForms.Android\bin\Debug\AndroidForForms.Android.dll (TaskId:631)
  Task Parameter:TypeLibFiles=G:\tfs\myapp\myapp\AndroidForForms\AndroidForForms.Android\bin\Debug\AndroidForForms.Android.tlb (TaskId:631)
  Task Parameter:AssemblyListFile=obj\AndroidForForms.Android.csproj.UnmanagedRegistration.cache (TaskId:631)
  Task Parameter:CreateCodeBase=True (TaskId:631)
  Registering assembly "G:\tfs\myapp\myapp\AndroidForForms\AndroidForForms.Android\bin\Debug\AndroidForForms.Android.dll" for COM Interop. (TaskId:631)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(4786,5): error MSB3217: Cannot register assembly "G:\tfs\myapp\myapp\AndroidForForms\AndroidForForms.Android\bin\Debug\AndroidForForms.Android.dll". Could not load file or assembly 'Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Done executing task "RegisterAssembly" -- FAILED. (TaskId:631)

'C:\Program' is not recognized as an internal or external command, operable program or batch file. ?

$
0
0

Hi'
I'm new to xamarin forms. I'm getting this error " 'C:\Program' is not recognized as an internal or external command,
operable program or batch file." when I try to run the android emulater. Any ideas on how to solve this problem.

Where do I find my 'App Bundle' file for nUnit testing

$
0
0

Can't seem to find the file location designated for the App Bundle when configuring nUnit testing project in my xamarin forms app

        app = ConfigureApp
                        .iOS
                        .AppBundle("/????)
                        .StartApp();

How can I Intercept children added to layout?

$
0
0

I have tried to:

layout.PropertyChanging += Layout_PropertyChanging;
layout.PropertyChanged += Layout_PropertyChanged;

where layout is a StackLayout.
But the PropertyChangedEventArgs e parameter to the event handlers , e.PropertyName is never "Children":

private void Layout_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
   if(e.PropertyName == "Children")
   {
       Console.WriteLine("Children changed") // <-- never happens when adding children to layout
   }
}

I have also noted the ChildAdded event - which does fire when a child is added. But it is not exactly what I am looking for.

Is it deliberate that Children property does not fire a propertychanged/propertywillchange - hiding it. Offering us developers ChildAdded and ChildRemoved events instead?

HOW TO FETCH DATA FROM SQLITE CORRESPONDING TO AN ID

$
0
0

I have saved some information in sqllite and how can i fetch data from sqllite corresponding to an id.

Xamarin Forms DisplayAlert option text not displayed.

$
0
0

We are using Display Alter for confirmation prompt which is working fine with the messages display. But text for confirmation event like 'Yes' or 'No' is not displaying, but click event is happening by click the position of the options.

Screen shot for reference.

Example Code:

        var result = await DisplayAlert("Confirm", "Are you sure to update delivery date?", "OK", "Later");
        if (result)
        {
     }

Any help or suggestions would be thankful.!

Is there some variable or function from which I can read the most recent build timestamp?

$
0
0

This could be useful in an "About" page.

How to reduce apk with Android App Bundle and how to build for 64-bit requirement

$
0
0

I have 2 questions both of them about building xamarin forms app for android for google play console, I will ask in one post

  1. I see in google play console that my apk would be smaller if I use Android App Bundle, is there an option in visual studio 2017 to do it? I also opened the apk with android studio and try to do it from there I couldn't make it

  2. Get your apps ready for the 64-bit requirement - I did the check https://developer.android.com/distribute/best-practices/develop/64-bit
    I found the armeabi-v7a I don't have the arm64-v8a or x86_64, so I have 32-bit , how should I build for for 64-bit requirement , is there a way with visual studio 2017 ? what should I do?

Layout problem

$
0
0

I'm new to Xamarin and I can't figure how to get rid of the gap between the two rows of my grid. I set all the margins and padding to zero that I could:

  <ListView x:Name="_listView"
            ItemSelected="OnListViewItemSelected"
            HasUnevenRows="True"
            >
    <ListView.ItemTemplate>
      <DataTemplate>
        <ViewCell>
          <Frame BorderColor="Black"
                 Margin="0"
                 Padding="0"
                 >
            <Grid>
              <Grid.RowDefinitions>
                <RowDefinition Height="30" />
                <RowDefinition Height="Auto" />
              </Grid.RowDefinitions>
              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="3*" />
                <ColumnDefinition />
              </Grid.ColumnDefinitions>
              <Label Text="{Binding Date}"
                     Margin="0"
                     />
              <Button Grid.Column="1"
                      Text="&lt;"
                      HeightRequest="30"
                      HorizontalOptions="End"
                      WidthRequest="50"
                      VerticalOptions="End"
                      Margin="0"
                      Padding="0"
                      />
              <Label Grid.Row="1"
                     Grid.ColumnSpan="2"
                     Text="{Binding Text}"
                     FontSize="Large"
                     LineBreakMode="WordWrap"
                     MaxLines="2"
                     Margin="0"
                     />
            </Grid>
          </Frame>
        </ViewCell>
      </DataTemplate>
    </ListView.ItemTemplate>
  </ListView>

The result looks has a big gap between the date and the body:

us.v-cdn.net/5019960/uploads/editor/iv/1suw2sz8fp3n.png

I'm trying to clone this app:

us.v-cdn.net/5019960/uploads/editor/gt/jfvqob5bb18t.jpg

I'd also like to know how to draw those ruled lines if anyone can help with that.

Thanks!

Android debug version runs yet release crashes

$
0
0

I am working on a Xamarin Forms app for Android and iOS phones. I am trying to get a release version over to QA. The release compiles with no errors. Running the app the splash screen displays and then crashes with

[AndroidRuntime] Shutting down VM
[AndroidRuntime] FATAL EXCEPTION: main
[AndroidRuntime] Process: com.raptortech.reunification.local, PID: 19063
[AndroidRuntime] android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class android.support.v7.widget.FitWindowsLinearLayout
[AndroidRuntime] Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class android.support.v7.widget.FitWindowsLinearLayout
[AndroidRuntime] Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.FitWindowsLinearLayout" on path: DexPathList[[zip file "/data/app/com.raptortech.reunification.local-JAxhHADWxd4TC35cIXcjAA==/base.apk"],nativeLibraryDirectories=[/data/app/com.raptortech.reunification.local-JAxhHADWxd4TC35cIXcjAA==/lib/x86, /data/app/com.raptortech.reunification.local-JAxhHADWxd4TC35cIXcjAA==/base.apk!/lib/x86, /system/lib]]
[AndroidRuntime] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
[AndroidRuntime] at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
[AndroidRuntime] at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
[AndroidRuntime] at android.view.LayoutInflater.createView(LayoutInflater.java:606)
[AndroidRuntime] at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
[AndroidRuntime] at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
[AndroidRuntime] at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
[AndroidRuntime] at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
[AndroidRuntime] at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
[AndroidRuntime] at android.support.v7.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:631)
[AndroidRuntime] at android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:518)
[AndroidRuntime] at android.support.v7.app.AppCompatDelegateImpl.onPostCreate(AppCompatDelegateImpl.java:299)
[AndroidRuntime] at android.support.v7.app.AppCompatActivity.onPostCreate(AppCompatActivity.java:98)
[AndroidRuntime] at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1342)
[AndroidRuntime] at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2964)
[AndroidRuntime] at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
[AndroidRuntime] at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
[AndroidRuntime] at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
[AndroidRuntime] at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
[AndroidRuntime] at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
[AndroidRuntime] at android.os.Handler.dispatchMessage(Handler.java:106)
[AndroidRuntime] at android.os.Looper.loop(Looper.java:193)
[AndroidRuntime] at android.app.ActivityThread.main(ActivityThread.java:6669)
[AndroidRuntime] at java.lang.reflect.Method.invoke(Native Method)
[AndroidRuntime] at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
[AndroidRuntime] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

In searching for a solution I did see others talk about a change from ?attr. I changed ?attr/actionBarSize to @dimen/abc_action_bar_default_height_material and ?attr/colorPrimary to @color/primary. The Android app still crashes. Any ideas what else could be cashing the issue?


How to trigger every change in the Entry field?

$
0
0

This the Entry Field which the user will input the data.

    <StackLayout Grid.Row="0" Grid.Column="0" Padding="16,13,16,9">
                    <StackLayout Orientation="Horizontal" Padding="10,0">
                      <StackLayout.GestureRecognizers>
                        <TapGestureRecognizer Tapped="OnTapVINRecognizer"/>
                      </StackLayout.GestureRecognizers>
                      <local:CustomLabel x:Name="VINLabel" Text="VIN" TextColor="#3680a4" Style="{StaticResource AccordTitleStyle}"/>
                      <Image x:Name="VINImage" Source="arrow_down.png"/>
                    </StackLayout>
                    <StackLayout x:Name="VINAccordion" IsVisible="True" Padding="0,5,0,16" Spacing="10">
                      <StackLayout Spacing="0" Orientation="Horizontal">
                        <local:CustomEntry x:Name="VINText" Placeholder="17 CHARACTERS" HorizontalOptions="FillAndExpand"/>
                      </StackLayout>
                      <local:CustomLabel Style="{StaticResource AccordLabelStyle}">
                        <local:CustomLabel.Text>
                          If the motor has a VIN, enter the VIN. A VIN is the 17 character identifier recorded on most vehicles built after 1998
                        </local:CustomLabel.Text>
                      </local:CustomLabel>
                      <local:CustomButton Clicked="OnClickSearchBtn" ClassId="vin"/>
                    </StackLayout>
                  </StackLayout>

I would like to capture every time the text changes cuz I will query the local db to check if there's a data matches from what the user inputted and then display the result below the field. How am I gonna do it in xaml?

Thanks for the suggestions and help.

Xamarin.Auth - Facebook NativeUi - How to change logged user?

$
0
0

I'm trying to implement Facebook NativeUI authentication in Xamarin.Forms PCL project for iOS, and have following problem.

I created authenticator in PCL library like this

authenticator = new OAuth2Authenticator(
                clientId: ClientId,
                scope: "",
                authorizeUrl: FB_AUTH_URI //can't post link in here in forum
                redirectUrl: FB_REDIRECT_URI //can't post link in here in forum
                getUsernameAsync: null,
                isUsingNativeUI: true
            )
            {
                AllowCancel = true,
                ShowErrors = false
            };

        authenticator.Completed += OnFacebookAuthCompleted;
        authenticator.Error += OnFacebookAuthError;

        AuthenticationState.Authenticator = authenticator;

        var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
        presenter.Login(authenticator);

It works fine, FB page ask for email and password and user can login without any problem with his credentials.

The problem is when user want to login next time with another Facebook account. After first successful login, next time, FB login screen looks different. This time there is a question "You previously logged in to TestApp with Facebook. Would you like to continue?" and there are "Continue" and "Cancel" buttons.

It is perfect if user want to use same account, but if want to login with another and click "Cancel" application receive Error message ("OAuth Error = Permissions+error") and browser redirect to new blank page and only way to login to another account is to delete app and install it again, if not FB keep asking to login to previously used.

I guess, it is some my mistake, but can't find any solution myself. When using "Facebook not nativeUI" or "Google nativeUI" everything works fine, but in this case have no idea what to do.

How can I force app to forget previous account?

And another question, is there a way to close native browser page after unsuccessfully login? When user login successfully the page close itself but in case of error stay on blank page like in this example.

Xamarin.LiveReload not showing my changes

$
0
0

This is the first time I'm going to ask for Xamarin.LiveReload
This is my 3rd month on Xamarin.LiveReload and today, It's getting a trouble showing my changes.

This is not actually the first time, but I was able to resolve the issue before just by doing CLEAN-REBUILD-RESTART_VS-REBUILD-RUN workaround and that pretty much solves the issue and my changes starts to appear on the emulator. But today, I cannot figure out why it's not showing my changes anymore.

I went back reading the TROUBLESHOOTING in this link
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/live-reload

But non of it really helps and I'm still having the issue.

I think I'm lost with other alternative to fix it. This is what I've done so far. Keep in mind that I always made sure that Live Reload is "Connected" and emu and my laptop is on the same network.

1st try
1. remove BIN and OBJ folder
2. CLEAN-REBUILD-RESTART_VS-REBUILD-RUN
(no luck)

2nd
1. Uninstall LiveReload and install it again
2. remove BIN and OBJ folder
3. CLEAN-REBUILD-RUN
(no luck)

3rd
1. Turn off firewall
2. remove BIN and OBJ folder
3. CLEAN-REBUILD-RUN
(no luck)

4th
1. Restart my laptop
2. uninstall Xamarin.LiveReload and install it again
3. remove BIN and OBJ folder
4. REBUILD-RUN
(no luck)

5th
1. Uncheck-check "Auto-generate encryption keys"
2. Restart VS
3. remove BIN and OBJ folder
4. CLEAN-REBUILD-RUN
(no luck)

6th
1. Uncheck "auto-generate encryption keys"
2. Restart VS
3. remove BIN and OBJ folder
4. CLEAN-REBUILD-RUN
(no luck)

does anyone have anymore suggestions?

Xamarin.livereload: Can't find package

$
0
0

Hello,
I am trying to compile a project (developed by others) that relies on the xamarin livereload package. Unfortunately I can't get this package to install.

I have downloaded the VSIX file as described in the documentation and that installed successfully, but I get this message from nuget when I open the project solution:
Error NU1101 Unable to find package Xamarin.LiveReload. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages, NuGet

I googled this and tried a variety of fixes, notably:

I tried multiple variations of this line in the console: install-package xamarin.livereload -prerelease -project myprojectname
And I opened the package manager, set 'source' to 'All' and ticked the 'include prerelease' button. Livereload shows up in the Installed tab of the package manager but states 'not available in this source'.

What am I missing here? I presume I need to add a new source to nuget or something equally similar but I'm not sure what that source is. Any tips?

ImageCell Image source not appearing

$
0
0

I have a ListView, with an ItemTemplate like so:

<ListView.ItemTemplate>
    <DataTemplate>
        <ImageCell Text="{Binding Name}"
            Detail="{Binding Description}"
            ImageSource="{Binding Image}" />
    </DataTemplate>
</ListView.ItemTemplate>

The list loads, but no images are visible. The Image is of type ImageSource and is loaded from a URL using ImageSource.FromUri.

If I refresh the list, some images might load, although I think now nothing ever happens (didn't think I changed anything).
When added to the list, Image is definitely set to an ImageSource with the url I gave.

Does anyone have any clues on how to fix this? (This is my first post so please excuse anything I do wrong)

Viewing all 91519 articles
Browse latest View live


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