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

Navigating and passing parameter to a TabbedPage child view's ViewModel in MVVM

$
0
0

What would be MVVM way of passing a parameter to the initial View's ViewModel, which is loaded into the detail area when navigating to the TabbedPage?

An example use case could be that I'm located in orders view, and click on one of the orders, it navigates me to the tabbed page that has order details view as the first tab. How do I pass the order details to the OrderDetailsViewModel? When using TabbedPage I have an additional layer in between. In my mind, the order details would have to be passed in a similar flow to this: OrdersViewModel ->TabbedPageViewModel -> OrderDetailsViewModel.

Is something like MessagingCenter viable solution for this type of communication?

I don't use MVVM Framework, but I wonder how would a frameworks like MvvmCross, Prism, MVVM Light would handle this scenario?


MessengingCentre Subscribe running twice although message was only send once.

$
0
0

// In my PCL
public ConstructorVM()
{
MessagingCenter.Unsubscribe(this, "Upload");
MessagingCenter.Subscribe(this, "Upload", message =>
{
//my codes

        });
    }

//In one of my listener in android platform
var message = new UploadMessage();
MessagingCenter.Send(message, "Upload");

Hi guys, as mentioned in the title, my subscribe codes ran twice even though my MessagingCenter send only ran once. When i first call the the ConstructorVM page, the codes work as per normal Messagingcenter only ran once, but however when I ran it leave and enter the ConstructorVM page again, it would run twice, it seems as though the subscription from the previous instance wasn't unsubscribed.

Any idea on how can I tackle this problem?

Error MT1006: Could not install the application

$
0
0

Hi all,

I have a cross-platform app (written using Xamarin Forms in a Shared Project) that I can compile fine and deploy fine to Android, but not so fine on iOS. I have followed the Xamarin-provided instructions here and here regarding creating certificates and profiles etc, but I get an error when trying to deploy on Release.

The steps I do:
1. Clean the solution
2. Rebuild the iOS project
3. Right-click on the iOS project, and click Deploy (Because Build -> Deploy is greyed out, and this is a workaround)

The solution builds fine, but on trying to deploy, I get the error:
Deploy failed. The app '<appName>.iOS' could not be deployed to the device 'iPhone'. Error: error MT1006: Could not install the application '<path>/<appName>.iOS.app' on the device 'iPhone': Your application failed code-signing checks. Check your certificates, provisioning profiles, and bundle ids. Probably your device is not part of the selected provisioning profile (error: 0xe8008015).

If I followed the instructions provided by the two links above, why am I getting this message?

What I can do is deploy on Release using a Developer profile. Why is this the case? What is happening, and how can I fix this?

If it helps, I'm using Visual Studio Community 2015 version 14.0.25425.01 Update 3, and Xamarin 4.5.0.443

Thanks

CarouselView state of the union?

$
0
0

What is the status of the CarouselView component? Here is what I think I know:

  1. Microsoft created CarouselPage but has deprecated it since it is not flexible since it is a Page and can't be used in a ContentPage
  2. Microsoft created CarouselView within Xamarin.Forms repo but it was too buggy so they moved it to its own repo
  3. Microsoft's CarouselView repo has been stagnant for 2 years
  4. alexrainman made his own which Microsoft like better so the plan was to incorporate his into the official Xamarin.Forms repo as the official CarouselView control
  5. alexrainman's CarouselView repo has been stagnant for 7 months
  6. I do not see alexrainman's CarouselView merged into Xamarin.Forms repo
  7. I see several bugs within alexrainman's CarouselView and I have even submitted a pull request for one of them

What CarouselView component should I use? Should I try Telerik's RadSlideView or SyncFusion's SfCarousel instead??

StaticResource OnPlatform for FontFamily

$
0
0

So my app uses the Hero custom font. I can declare it just fine this way:

<Style ApplyToDerivedTypes="True" TargetType="Label">
                <Setter Property="TextColor" Value="{StaticResource TextWhite}"/>
                <Setter Property="FontFamily">
                    <Setter.Value>
                        <OnPlatform x:TypeArguments="x:String">
                            <On Platform="iOS" Value="Hero"/>
                            <On Platform="Android" Value="Hero.otf#Hero"/>
                        </OnPlatform>
                    </Setter.Value>
                </Setter>
            </Style>

However, to be able to use it on different spots throughout the app (such as an Autocomplete field from Syncfusion, which has like 3 different FontFamily properties), I wanted to create a separate StaticResource just for the OnPlatform, like this:

        <OnPlatform x:Key="OnPlatformHeroFont" x:TypeArguments="x:String">
                <On Platform="iOS" Value="Hero"/>
                <On Platform="Android" Value="Hero.otf#Hero"/>
            </OnPlatform>

And then use a reference to it (Value="{StaticResource OnPlatformHeroFont}") both in the Syncfusion field and in the other Styles in the App.xaml file:

<Style ApplyToDerivedTypes="True" TargetType="Label">
                <Setter Property="TextColor" Value="{StaticResource TextWhite}"/>
                <Setter Property="FontFamily" Value="{StaticResource OnPlatformHeroFont}"/>
</Style>

However, this gives me a "Java.Lang.RuntimeException: Font asset not found Hero.otf#Hero" exception, while that first example (declared inside a style's setter tag) doesn't. Any ideas?

And yes, the font is inside of the Assets folder. As I said, it works fine in that first example.
Also, works fine on iOS.

What's the best way to set UI profiles (allow the user to select different colour schemes)?

$
0
0

Hey, I'm working on a project and it needs to allow users to adjust the UI to match their preferences.

At the moment what I'm doing is using App.Current.Resources and setting values like "boxColour" = Color.Black; and "standardIconHeight" = 0.1*screenHeight.

My issue comes now that I am trying to segregate my Logic and UI into separate projects. That is to say:
project.Logic contains my models, viewmodels and services.
project.Views contains my xaml pages, controls, converters and composition root (App.xaml.cs).

My issue is that project.Logic does not reference project.Views. So I can't access App.Current.Resources. This means when the user presses the "Select Colour Scheme" button, I can't change App.Current.Resources from my viewmodel.

I've considered combining the projects, but this is generally a sign of very bad code design (tight coupling between layers). So I'm wondering if there is a good alternative?

Thanks for any help.

How to set DatePicker value equal yesterday in xaml in xamarin.form?

$
0
0

To set the Date attribute in xaml equal today we can use Today attribute as following:

xmlns:system="clr-namespace:System;assembly=mscorlib"
<DatePicker Date="{x:Static system:DateTime.Today}"/>

I've tried to set it by using AddDays method but it couldn't help.

<DatePicker Date="{x:Static system:DateTime.Today.AddDays(-1)}"/> Does not work.

So is there a way?

Modal page with dismiss/close button.

$
0
0

Hello,
I would like to open a modal page that have a navigation bar with a "X" (cross) at the top left of the page to close/dismiss the page, like showed in Android documentation about bottom sheets

Do you have any idea how can I achieve that in Xamarin.Forms ?

Thanks !


Animations simply won't run with Samsung S7 Android 8.0

$
0
0

I'm having a weird issue with animations (such as TranslateTo method, any other anim method won't run also) in Xamarin Forms which makes every animated view to skip all the transitions and anim duration. The final result of my animations on this device is actually the view jumping/teleporting to its final destination in an instant (ignoring anim duration).

Decided to try the 'Easing' animation sample, but clicking 'run animation' button will simply teleport the image to the final position instantly.

To make sure this was related to this specific device, I tried the same sample (and other apps I built) with two other devices:

  • Motorola XT1040 Android 5.1
  • Samsung A5 2017 (SM-A520F) Android 8.0

Both could run the animations just fine.

I must add that I could run animations on my S7 before, but I lost track of when exactly it stopped working because I was working on other things that had no animations, so I can't precisely tell if it was some recent XF nuget update, firmware or even android API that caused this.

Also, no luck googling for similar cases, so I was left with the last choice of asking here for help.

Additional info about my phone:

  • Non-rooted
  • SM-G930F
  • Android 8.0

XForms version 3.4.0.1008975

Any help is appreciated. Thanks

CrossGeolocator GetPositionAsync exits loop/method

$
0
0

Hello. I want to keep the phone's location quite often in an App, so I'm using the GetPositionAsync method, and keep calling that. I've written some code, and when I attach that in a simple OnAppearing method everything works fine. If I write it in a method or while loop, when it gets to the GetPositionAsync or some other local database things, I think only awaitable methods, it goes right out of the loop/method. I am using async. Any ideas?

var locator = CrossGeolocator.Current;
                locator.DesiredAccuracy = 20;

                var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(10));

                location.Latitude = position.Latitude;
                location.Longitude = position.Longitude;

                await App.LocationDatabase.SaveLocationAsync(location);

                await Task.Delay(TimeSpan.FromSeconds(10));

How to update progressbar from customwebview renderer in xamarin forms for android?

$
0
0

I'm new to Xamarin Forms and I'm struggling on how to update a ProgressBar from a WebView using a custom renderer for the webview.

In android you can do something like this, with the progressbar and webview that are in the main_layout.xml

public class MainActivity extends Activity {

    private ProgressBar progressBar;
    private WebView webView;    

    @Override
    protected void onCreate(Bundle savedInstanceState) {     
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_layout);

        progressBar = (ProgressBar) findViewById(R.id.progress);
        webView = (AdvancedWebView) findViewById(R.id.webView);
        // webview initialisation
        webView.setWebViewClient(new WebViewClient(this) {
            @Override
            public void onPageFinished(WebView view, String url) {
                // update progressbar
                progressBar.setVisibility(View.GONE);
            }
        });
    }
}

In Xamarin Forms I have this layout in MainPage.xaml in the shared project

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="MainPage"
NavigationPage.HasNavigationBar="False">

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <ProgressBar
        x:Name="progress"
        Grid.Row="3"
        HorizontalOptions="FillAndExpand"
        Progress="0"
        VerticalOptions="Center" />

    <WebView
        x:Name="webview"
        Grid.Row="0"
        Grid.RowSpan="4"
        Grid.Column="0"
        HorizontalOptions="FillAndExpand"
        IsVisible="False"
        Source="URL"
        VerticalOptions="FillAndExpand" />

</Grid>

public partial class App : Application
{
    public App ()
    {
        InitializeComponent();

        MainPage = new MainPage(); 
    }
}

And this custom webview render for android in the android project

[assembly: ExportRenderer(typeof(WebView), typeof(CustomWebviewRenderer))]
namespace MyApp.Droid
{
    public class CustomWebviewRenderer : WebViewRenderer
    {
        private readonly Context context;

        public CustomWebviewRenderer(Context context) : base(context)
        {
            this.context = context;
        }

        protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
        {
            base.OnElementChanged(e);
            var formsWebView = e.NewElement as Xamarin.Forms.WebView;

            if (formsWebView != null)
            {
                var webView = Control as Android.Webkit.WebView;
                webView.SetWebViewClient(new CustomWebViewClient());           
                webView.Settings.LoadWithOverviewMode = true;
                webView.Settings.UseWideViewPort = true;
                SetNativeControl(webView);
            }
        }

        private class CustomWebViewClient : WebViewClient
        {
            public override void OnPageFinished(Android.Webkit.WebView view, string url)
            {
                // how to update progressbar?
                base.OnPageFinished(view, url);
            }

            public override void OnPageStarted(Android.Webkit.WebView view, string url, Bitmap favicon)
            {
                base.OnPageStarted(view, url, favicon);
            }

            public override bool ShouldOverrideUrlLoading(Android.Webkit.WebView view, IWebResourceRequest request)
            {
                return base.ShouldOverrideUrlLoading(view, request);
            }
        }
    }
}

How can I update the ProgressBar that I have in my MainPage.xaml from the OnPageFinished in the CustomWebviewRenderer class to show the webpage has finished loading? Should I use the MainActivity.cs in the Android project?

Can someone point me in the right direction on how to solve this?

how to get listview position arralist value when i click on label in listview and get postion data

$
0
0
        <ListView
            SelectionMode="None"
            SeparatorColor="#f8f8f8"
            x:Name="flightlist"

            Margin="2"
            BackgroundColor="#f8f8f8"
            HasUnevenRows="true"
            RowHeight="300">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout
                            Margin="10"
                            Orientation="Vertical"
                            HorizontalOptions="FillAndExpand">

                           <Label text={ Binding name}?> 
                    <Buton text="buy book " x:name="btn" click="btn clicked" > 

                           </StackLayout>

Swipe to previous page like Telegram

$
0
0

How create swipe to back?

In iOS:

`

[assembly: ExportRenderer(typeof(HIPSTO.Controls.CustomContentPage), typeof(HIPSTO.iOS.Platform.Renderers.IOSPageRenderer))]     
namespace HIPSTO.iOS.Platform.Renderers 
{
  public class IOSPageRenderer : PageRenderer        
  {         
      public override void ViewWillAppear(bool animated)            
      {              
           base.ViewWillAppear(animated);

            ViewController.NavigationController.InteractivePopGestureRecognizer.Enabled = true;
            ViewController.NavigationController.InteractivePopGestureRecognizer.Delegate = new UIKit.UIGestureRecognizerDelegate();
       }
   }
}`

But it only works from the edge. It is necessary from any place.
No ideas with android

As below shown:

MvvmCross: Modal dialog that is not not fullscreen and more like popup

$
0
0

Hi,
is it possible to show a modal dialog using MvvmCross in Xamarin Forms that doesn't take up the whole screen?
I am using the 'MvxModalPresentation' attribute from the MvvmCross Playground repository.
I need the modal dialog to be a popup that has a semi-transparent background behind it.
I think it's currently not possible by default (see MvvmCross issue #2794), but if you have any suggestions as to what I could do to implement this, I would be eternally grateful!

Regards,
Stepan

In-door way-finding navigation with beacons

$
0
0

Hi

I'm in the middle of creating a cross-platform hospital appointment booking app. Is it possible to create an in-door navigation feature using beacons? I can't find much info on the subject.

Thanks.


Access files on a file server

$
0
0

I have to develop a business cross platform application which has to read data residing in a CSV file on a file server or a workstation. The app has to work offline with the data and write a file which has to be copied to the server/workstation when the device is online again.

I can't change the data format on the server side.

What is the best approach for it?

System.Net.Http.HttpRequestException exception will running the UI Test on Physical Device..

$
0
0

I have created a simple Xamarin.Forms(Portable) project and included UI Test project in it. But when i am trying to run the test in physical device it giving me below mentioned exception.

Test Name:  AppLaunches
Test Outcome:   Failed
Result Message: 
SetUp : System.Net.Http.HttpRequestException : An error occurred while sending the request.
  ----> System.Net.WebException : The underlying connection was closed: The connection was closed unexpectedly.
Result StandardOutput:  Full log file: C:\Users\Admin\AppData\Local\Temp\uitest\log-2016-10-22_11-04-53-698.txt
Skipping IDE integration as important properties are configured. To force IDE integration, add .PreferIdeSettings() to ConfigureApp.
Android test running Xamarin.UITest version: 2.0.0.1534
Initializing Android app on device ZX1D63GCCL with installed app: co.veloxcore.UITestSample2
Signing apk with Xamarin keystore.
Skipping installation: Already installed.

Here is the link to my project: XamarinUITest

What is the best GIF library you have ever used?

$
0
0

What is the best GIF library you have ever used and it works perfectly with both Android and iOS?

I have tried FFImageLoading but it does not work on my HTC mobile according to this issue.

I have also tried Lottie (that deals with .json instead of .gif and I've downloaded some .json samples) and it works fine with all devices I have tested on, but I can't perfectly create my custom .json file for it by AfterEffects, I've already created but it has problems (I think related to frequency and other stuff) that I couldn't solve.

So sharing your experience would be so helpful.

Don't lose focus when clicked anywhere but entry

$
0
0

I have an issue with the focus. When I click anywhere but an entry , the entry loses focus. This behaviour isn't what I want for my application.
If I click on a blank space the focus shouldn't be lost. However if I click on another Entry it should focus the entry I just clicked.

Does anybody here know how to overcome this issue? Would appreciate the help alot.

Are there any Good Examples of a list view with as Sublist using data from web API?

$
0
0

Are there any Good Examples of a list view with as Sub-list using data from web API?

I all,

Would anyone know if there is an example of how one would created a sub-list with in a list view
using data returned from a web Api.

I have seen some example videos but the data is typed it.. they don't show how one would do this with database data
as well as how you would relate the data of the parent list to the child..

Most of the examples I have seen have been users hard coding data.

THanks for any help in advance.

Viewing all 91519 articles
Browse latest View live


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