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

PullToRefresh does not work with custom ListViewRenderer in iOS

$
0
0

I'm trying to use grouped style in iOS UITableView and created a custom ListViewRenderer. The grouped style worked, but the PullToRefresh stop to work. I tested and when I don't use my custom renderer, the PullToRefresh works, but when I use the custom renderer, Pull To Refresh doesn't work.

Can anyone help me?

Here is my renderer:

public class CustomTableViewRenderer : ListViewRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
        {
            base.OnElementChanged(e);

            if (Control != null && e.NewElement != null)
            {
                Control.TableFooterView = new UIView(CGRect.Empty);

                if (e.NewElement.IsGroupingEnabled)
                {
                    var groupedTableView = new UITableView(Control.Frame, UITableViewStyle.Grouped);
                    groupedTableView.Source = Control.Source;

                    if (e.NewElement.IsPullToRefreshEnabled)
                    {
                        groupedTableView.RefreshControl = Control.RefreshControl;
                    }

                    SetNativeControl(groupedTableView);
                }
            }
        }
    }

Here is my xaml:

<ContentPage.Content>
        <AbsoluteLayout>
            <ListView x:Name="ListViewPacientes" 
                      ItemsSource="{Binding PacientesAgrupados}"   
                      GroupDisplayBinding="{Binding Key}"
                      IsGroupingEnabled="true"
                      HasUnevenRows="True"
                      AbsoluteLayout.LayoutBounds="0,0,1,1" 
                      AbsoluteLayout.LayoutFlags="All"
                      IsPullToRefreshEnabled="true"
                      IsRefreshing="{Binding IsBusy}"
                      RefreshCommand="{Binding LoadPacientesCommand}"
                      IsEnabled="{Binding CanNavigate}">
                <ListView.GroupHeaderTemplate>
                    <OnPlatform x:TypeArguments="DataTemplate">
                        <OnPlatform.Android>
                            <DataTemplate>
                                <ViewCell>
                                    <customViews:GroupHeaderView/>
                                </ViewCell>
                            </DataTemplate>
                        </OnPlatform.Android>
                    </OnPlatform>                    
                </ListView.GroupHeaderTemplate>
                <ListView.Behaviors>
                    <behaviors:EventToCommandBehavior 
                        EventName="ItemTapped" 
                        Command="{Binding PacienteSelectCommand}" 
                        EventArgsConverter="{StaticResource ItemToObject}"/>
                </ListView.Behaviors>
                <ListView.Margin>
                    <OnPlatform x:TypeArguments="Thickness">
                        <On Platform="Android" Value="{StaticResource margemPagina}"/>
                    </OnPlatform>
                </ListView.Margin>
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <ViewCell.Height>
                                <OnPlatform x:TypeArguments="x:Double">
                                    <On Platform="Android" Value="56"/>
                                </OnPlatform>
                            </ViewCell.Height>
                            <ContentView>
                                <ContentView.BackgroundColor>
                                    <OnPlatform x:TypeArguments="Color" iOS="White"/>
                                </ContentView.BackgroundColor>
                                <RelativeLayout>
                                    <Label                                        
                                        Text="{Binding Nome}"
                                        RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1.0}" 
                                        RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.5}" 
                                        FontSize="{StaticResource fontSize_textoPrimario}"
                                        TextColor="{StaticResource cor_textoPrimario}"
                                        XAlign="Start"
                                        YAlign="End"
                                        LineBreakMode="TailTruncation">
                                        <Label.Margin>
                                            <OnPlatform x:TypeArguments="Thickness">
                                                <On Platform="iOS" Value="18, 4, 0, 0"/>
                                            </OnPlatform>
                                        </Label.Margin>
                                    </Label>

                                    <Label
                                        Text="{Binding InfoPaciente}"               
                                        RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.5}"                     
                                        RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1.0}" 
                                        RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.5}" 
                                        FontSize="{StaticResource fontSize_textoSecundario}"
                                        TextColor="{StaticResource cor_textoSecundario}"
                                        XAlign="Start"
                                        YAlign="Start"
                                        LineBreakMode="TailTruncation">
                                        <Label.Margin>
                                            <OnPlatform x:TypeArguments="Thickness">
                                                <On Platform="iOS" Value="18, 6, 0, 4"/>
                                            </OnPlatform>
                                        </Label.Margin>
                                    </Label>
                                </RelativeLayout>
                            </ContentView>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
            <ContentView                 
                AbsoluteLayout.LayoutBounds="1, 1, 100, 100"                
                AbsoluteLayout.LayoutFlags="XProportional,YProportional">
                <OnPlatform x:TypeArguments="View">
                    <OnPlatform.Android>
                        <customViews:FloatingActionButtonView
                            Elevation="12"
                            BackgroundTint="{StaticResource Accent}" 
                            ImageName="ic_add.png" 
                            Size="Normal"
                            Command="{Binding AdicionarCommand}"/>
                    </OnPlatform.Android>
                </OnPlatform>
            </ContentView>
        </AbsoluteLayout>
    </ContentPage.Content>

can't access rest-API after a while because of DB connection is closed.

I updated Xamarin.Forms on visual studio (Android package) and I am not able to build a project now

$
0
0

I updated Xamarin.Forms on visual studio (Android package) and I am not able to build a project now, I am getting following errors error: cannot access AutoSizeableTextView ButtonRenderer.java error: cannot access NestedScrollingParent2 SwipeDismissBehavior_OnDismissListenerImplementor.java error: cannot access NestedScrollingChild2 RecyclerView_ItemAnimator_ItemAnimatorFinishedListenerImplementor.java I am assuming this issue is related to updated Xamarin.Forms package, is there any way to downgrade to earlier version or fix these java files?

how can i run my ios xamarine forms project with old version of ios?

$
0
0

hi ,
I'm Mbarki Mohamed an new xamarin forms developer . So i have some problems with this language i developed a project with my visual Studio 2017.In my mac i have xcode 9.3 with ios sdk 11.3.But my client fix To me the target of ios version that 6.1.6.
How can i fixed ?
thank you

How to crop images in Xamarin.Forms via code like WPF CroppedBitmap class does

$
0
0

Hi guys,
Nice to meet you. I'm new to Xamarin.Forms and I'm not very good with it. I'd like to implement a "15 puzzle"-style game, using images instead of numbers, in Xamarin.Forms on Visual Studio 2017 (on a Windows 10 Pro machine) so I need a way to slice an image in pieces, via code, in a very simple manner. In WPF it was pretty easy thanks to CroppedBitmap class in System.Windows.Media.Imaging namespace but nothing like this seems to be available for Xamarin.Forms, at least I was not able to find something like this. Is there something embedded or a third-party library that can do that possibly in a simple manner as CroppedBitmap class does and possiby for all the platforms?
Thanks for your attention.
Kisses
Philomena

Xamarin Auth to store credentials on iOS and Android using PCL

$
0
0

Does anyone have a basic working example on how to implement this package. I have seen bits and pieces but don;t have the full picture.

Thanks

ListView SelectedItem using MVVM, XAML and ReactiveUI

$
0
0

I'm new to Xamarin and developing a mobile app using ReactiveUI and XAML. I'm having difficulty trying to execute a Command when the user clicks on a listview item.

The first problem was getting the selected item event working. I solved this using Attached Behaviors as described here: https://forums.xamarin.com/discussion/comment/215767/#Comment_215767

Using the above technique I managed to show the DisplayItem.Name corresponding listview item clicked.

Great, but that's only half the battle. Now I would now like to modify this code to:

  1. Use ReactiveUI bindings (if possible)
  2. Execute a command (eg., navigate to settings page)

Background:
The page I'm working on displays a listview of DashboardItems like: Settings, Edit Profile, My Messages, etc., each would navigate to a different page.

   public class DashboardItem
    {
        public string Icon { get; set; }
        public string Name { get; set; }
        //public ReactiveCommand Command { get; set; }
    }

Using the Attached Behavior method when the user clicks a row in the listview, a DashboardItem object is returned. Figured I could modify the DashboardItem class by adding a ReactiveCommand property. Then it would just be a matter of invoking the command right? Uh, not so easy as I found out. After hours of reading and cut/paste code snippets I'm thoroughly lost, my code looks like crap, and I've decided I needed to get some help.

Here's the XAML...

<ui:ContentPageBase xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:rxui="clr-namespace:ReactiveUI.XamForms;assembly=ReactiveUI.XamForms" xmlns:ui="clr-namespace: PTS_v1.Views; assembly=PTS_v1" xmlns:vms="clr-namespace:PTS_v1.ViewModels; assembly=PTS_v1" xmlns:image="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin.Abstractions" xmlns:local="clr-namespace:PTS_v1" xmlns:controls="clr-namespace:PTS_v1.Controls; assembly=PTS_v1" x:TypeArguments="vms:DashboardViewModel" x:Class="PTS_v1.Views.DashboardPage">
    <ContentPage.Content>
        <StackLayout VerticalOptions="Fill" BackgroundColor="#1b1b22" Spacing="0">
            <ListView x:Name="DashboardItemListView" CachingStrategy="RecycleElement" Margin="6, 0, 6, 0" HasUnevenRows="True" controls:ItemTappedAttached.Command="{Binding ItemTapCommand}">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout HeightRequest="50" Orientation="Horizontal" Spacing="20">
                                <StackLayout HorizontalOptions="Start"></StackLayout>
                                <Label VerticalTextAlignment="Center" Text="{Binding Icon}" Style="{StaticResource FontAwesome}" TextColor="White" FontSize="20" />
                                <Label Text="{Binding Name}" Style="{DynamicResource FontLabel}" TextColor="White" FontSize="18" VerticalOptions="Center" HorizontalOptions="Center">
                                    <Label.FontFamily>
                                        <OnPlatform x:TypeArguments="x:String">
                                            <On Platform="iOS" Value="OpenSans-Bold" />
                                            <On Platform="Android" Value="font/OpenSans-Bold.ttf#OpenSans-Bold" />
                                        </OnPlatform>
                                    </Label.FontFamily>
                                </Label>
                                <StackLayout HorizontalOptions="EndAndExpand"></StackLayout>
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
            <Label TextColor="White" x:Name="DisplayLabel" HorizontalTextAlignment="Center" FontSize="18" />
        </StackLayout>
    </ContentPage.Content>
</ui:ContentPageBase>

Here's the code behind...

public partial class DashboardPage : ContentPageBase<DashboardViewModel>
    {
        public DashboardPage()
        {
            InitializeComponent();
        }
        protected override void OnAppearing()
        {
            base.OnAppearing();
            this.WhenActivated(disposables =>
            {
                this.OneWayBind(ViewModel, x => x.DashboardItems, x =>
                  x.DashboardItemListView.ItemsSource).DisposeWith(disposables);

                this.Bind(ViewModel, vm => vm.DisplayText, c => c.DisplayLabel.Text)
                .DisposeWith(disposables);
            });
        }
    }

Here's the ViewModel method which displays the name of the listview selected item...

public Command ItemTapCommand
    {~~~~
        get
        {
            return new Command((o) =>
            {
                var item = o as DashboardItem;
                if (item != null)
                {
                    SelectedDashboardItem = string.Format("{0} selected", item.Name);
                }
            });
        }
    }

I want do something like this...

public ReactiveCommand ItemTapCommand
        {
            get
            {
            // somehow get the command parameter <DashboardItem>
                    var item = o as DashboardItem;
                    if (item != null)
                    {
            return item.DashCommand;
                    }
                });
            }
        }

Any ideas or tips if I'm on the right track, or how I can paste this all together would be awesome!

Listview with Xaml ContentView as the DataTemplate

$
0
0

I have a ListView. I would like the ItemTemplate/DataTemplate to be a piece of reusable xaml. Here is my Code.

        <ListView 
            HorizontalOptions="Fill"
            ItemsSource="{Binding MyList, Mode=OneWay}"
          <ListView.ItemTemplate>
            <DataTemplate>
              <views:ItemTemplate/>
            </DataTemplate>
          </ListView.ItemTemplate>
        </ListView>

And my Item's xaml

<?xml version="1.0" encoding="UTF-8"?>
<ViewCell xmlns="http://xamarin.com/schemas/2014/forms"
          xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
          x:Class="Views.ItemTemplate">
  <ViewCell.View>
    <Label Text="Name" TextColor="White"></Label>
  </ViewCell.View>
</ViewCell>

The result is a null reference exception. I have also tried using a ContentView with the same result. Please advise.


How to hide back button in Xamarin.Forms

$
0
0

How to hide back button in Xamarin.Forms? Please help

Taking a Picture and Saving the Photo to a Directory within the Crossplatform App

$
0
0

Hello -
I am new to using Xamarin Forms. I want to create the functionality for a multi-platform app of taking a picture and saving the photo to a directory within the crossplatform app. Does anyone know how I would do this? Any help is greatly appreciated! Thanks!

Generic versions of Create () are no longer supported and deprecated

$
0
0

When updated to Xamarin.Forms 2.1 I got the following compilation error

_ Generic versions of Create () are no longer supported and deprecated_

Why? It looks as a step backwards.

CarouselPage, Scrollview, SetHasNavigationBar(this, false) and SetUseSafeArea behaves incorrect

$
0
0

I have a Carousel page with children and NavigationPage.SetHasNavigationBar(this,false);. The child has a scrollview and label inside the scrollview.
As a result the scrollview in child is always scrollable even if there is no needs in this and content of the child jumps around a page.
I know that this was a bug for ContentPage as well and was fixed in some earlier versions of Xamarin forms you was need to add On<Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true);
Seems like this does not apply to Carousel page because the content still behaves incorrect and jumps.
Does somebody know the solution for Carousel page?
Pictures and sample project to reproduce attached.
XF package is 2.5.0.280555
Thanks.
https://dropbox.com/s/mkzdbzbk1a27a5a/App6.rar?dl=0

UWP: Extended Splash Screen

$
0
0

This question should be in Windows or UWP subforum. Because there isn't such one available I post it unter Xamarin.Forms. I'm currently looking into Extended Splash Screen (also see here).

First I took a Xamarin Forms Shared Project and added the code from the MS link. Then I looked for the adaptions in the second link to knwo what has been changed for UWP. One of the things I did is to remove the reference of System, because there was a conflict with Microsoft.NETCore.UniversalWindowsPlatform. You can find my project in the attachment (I removed the packages folder to save space).

Now I found out that you only can have a icon/picture in the middle of the screen and a background color. The only thing you can do more than with the normal splash screen is to display a progress ring or other loading informations.

What is not working for me is if you turn the device from Portrait to Landscape while starting up the app. In landscape everything is in the wrong position. How can I get the current screen width? This is my current code:

   void PositionImage()
    {
        extendedSplashImage.SetValue(Canvas.LeftProperty, splashImageRect.Left);
        extendedSplashImage.SetValue(Canvas.TopProperty, splashImageRect.Top);
        extendedSplashImage.Height = splashImageRect.Height / ScaleFactor;
        extendedSplashImage.Width = splashImageRect.Width / ScaleFactor;
    }

    void PositionRing()
    {
        splashProgressRing.SetValue(Canvas.LeftProperty, splashImageRect.X + (splashImageRect.Width * 0.5) - (splashProgressRing.Width * 0.5));
        splashProgressRing.SetValue(Canvas.TopProperty, (splashImageRect.Y + splashImageRect.Height + splashImageRect.Height * 0.1));
    }

splashImageRect is set/updated in ExtendedSplash_OnResize:

splashImageRect = splash.ImageLocation;

I also tried to use SizeChanged but I always get 1280 as height and 720 as width no matter what the orientation is. The sample code from Microsoft puts the Image into a Viewbox and has a different PositionImage method (the downloadable Visual Studio solution differs from the code on the website).

Now I tried to use the ViewBox:

 <Viewbox Stretch="Uniform">
    <Image x:Name="extendedSplashImage" Source="Assets/SplashScreen.png" />
    <!--<ProgressRing Name="splashProgressRing" IsActive="True" Width="20" HorizontalAlignment="Center"></ProgressRing>-->
  </Viewbox>

and adapted the PositionImage() method:

extendedSplashImage.SetValue(Viewbox.HeightProperty, splashImageRect.Height);
extendedSplashImage.SetValue(Viewbox.WidthProperty, splashImageRect.Width);

The orientation now works, but the size of the picture (splash image) differs between

  • app start and when
  • the ExtendedSplash page is shown (with the progress ring)

in the same portrait orientation. How can I match the splash image with the extended splash image?

Remove extra gap between keyboard and scrollview, when trying to enter data in Editor

$
0
0

Hi,

I am creating a normal Contact us form. All my controls and labels are placed inside a stack layout. And I added this stacklayout to ScrollView ( as seen below )

The problem is whenever I tap the Message editor box from my iPhone, a virtual keyboard shows up and it pushes the current showing ScrollView above(it's okay so far) , and as the ScrollView goes up, it creates extra space below message editor box and Keyboard(as in imager below.

.
.
To say it simple,

.
.
Entry focus -> keyboard shows up -> the keyboard pushes the entire ScrollView up -> generate extra space below the last element, so there is a gap between the last element and the keyboard.
.
.

Please share your knowledge here.

Thanks.

How to navigate a specific tab to root in Xamarin.Froms using Prism

$
0
0

In my app I am using Prism and have a TabbedPage with multiple tabs. I know I can Navigate the app using urls such as TabbedPage/NavigationPage/SomePage and navigate absolutely by doing something like /TabbedPage/NavigationPage/SomePage, but how do I navigate just one tab (the currently selected tab) back to root for example? I'm assuming if I use the absolute url it will reset the whole stack including the TabbedPage and I don't want to do that, I just want to reset that particular tab's NavigationPage back to root.


BoxView custom renderer LongClick not working in Xamarin Android

$
0
0

Hi!

I have a BoxView with a LongClick event in my app, and it has stopped working. It is not something that I use often, so I'm not sure since when it has started to fail. On iOS it is working properly.

I have attached a sample project to show the problem. In this project there are two BoxView and one Button. The button is there to show that the LongClick works.

The left BoxView should show a message on a LongClick. The right BoxView shows a message when touched, just to clarify that its events are working.

Someone has faced this problem before? Does anyone know a workaround? I would prefer not having to update Xamarin Forms right now.

Thanks!

iOS - mscorlib.dll was not found or could not be loaded

$
0
0

Hello,

Someone has any idea about this issue? That stuck me harder :/

1>  MONO_PATH=/Users/MySolution/Library/Caches/Xamarin/mtbs/builds/MyProject.iOS/f9d974787ab62efe2a9dd70fce684ce0/C:/Users/Tony/AppData/Local/Temp/vs832E.tmp/iPhone/Debug/mtouch-cache/64/Build /Library/Frameworks/Xamarin.iOS.framework/Versions/11.9.1.24/bin/arm64-darwin-mono-sgen --debug -O=gsharedvt -O=-float32  --aot=mtriple=arm64-ios,data-outfile=/Users/MySolution/Library/Caches/Xamarin/mtbs/builds/MyProject.iOS/f9d974787ab62efe2a9dd70fce684ce0/C:/Users/Tony/AppData/Local/Temp/vs832E.tmp/iPhone/Debug/mtouch-cache/arm64/System.Core.aotdata.arm64,static,asmonly,direct-icalls,full,dwarfdebug,no-direct-calls,direct-pinvoke,outfile=/Users/MySolution/Library/Caches/Xamarin/mtbs/builds/MyProject.iOS/f9d974787ab62efe2a9dd70fce684ce0/C:/Users/Tony/AppData/Local/Temp/vs832E.tmp/iPhone/Debug/mtouch-cache/arm64/System.Core.dll.s "/Users/MySolution/Library/Caches/Xamarin/mtbs/builds/MyProject.iOS/f9d974787ab62efe2a9dd70fce684ce0/C:/Users/Tony/AppData/Local/Temp/vs832E.tmp/iPhone/Debug/mtouch-cache/64/Build/System.Core.dll"
1>  '/Users/MySolution/Library/Caches/Xamarin/mtbs/builds/MyProject.iOS/f9d974787ab62efe2a9dd70fce684ce0/C' in MONO_PATH doesn't exist or has wrong permissions.
1>  '/Users/Tony/AppData/Local/Temp/vs832E.tmp/iPhone/Debug/mtouch-cache/64/Build' in MONO_PATH doesn't exist or has wrong permissions.

1>  The assembly mscorlib.dll was not found or could not be loaded.
1>  It should have been installed in the `/Users/builder/data/lanes/5909/f62de472/source/xamarin-macios/builds/install/cross64/lib/mono/4.5/mscorlib.dll' directory.

Best regards

WebView: Cannot call determinedVisibility()

$
0
0

Hey folks,

I'm currently using a Xamarin.Forms.Webview for displaying web content. On iOS this works without any issues. However, on Android the debugger outputs this message everytime:

W/cr_BindingManager( 3824): Cannot call determinedVisibility() - never saw a connection for the pid: 3824

This is the containing view (links removed as I'm new here):

<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="" xmlns:x="" x:Class="MyApp.Views.NewsDetailPage" Title="{Binding Title}"> <StackLayout x:Name="layout" Spacing="20" Padding="15"> <Label Text="{Binding News.Title}" FontSize="Medium"/> <Label Text="{Binding News.Date}" FontSize="Small"/> <Button Text="Load" BackgroundColor="DarkGray" FontSize="16" Clicked="OnLoad" /> <WebView x:Name="newsDisplay" HorizontalOptions="FillAndExpand " VerticalOptions="FillAndExpand"> </WebView> </StackLayout> </ContentPage>

It doesn't matter whether the source attribute is set in the XAML or the CS file.

As far as I can tell, the website is loaded because the scroll bars change in size and range. Yet, the entire website stays white. There's no difference between a virtual and a physical device. What am I missing here? Any help would be appreciated!

Border radius

$
0
0

Hello! When I entered the border radius in UWP appeared on the focus with the cursor in angles another color and angles is square. It is possible to fix it ?

SplashScreen Activity OnCreate Event Not Firing

$
0
0

Hi,

I'm having some trouble implementing my splash screen for my app. I have the splash screen showing up with my image ok but it doesnt continue on to my MainActivity. When I attempt to debug none of my breakpoints on the OnCreate method of the Splash Screen Activity get hit. I dont think its getting there at all and all im left with is my splash screen on the app.

Here is my Splash Screen Activity Code

 [Activity(Theme = "@style/Theme.Splash", MainLauncher = true, NoHistory = true)]
    public class SplashActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {

        public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
        {
            base.OnCreate(savedInstanceState, persistentState);

            StartActivity(new Intent(Application.Context, typeof(MainActivity)));
        }



    }

Any ideas would be much appreciated.

Viewing all 58056 articles
Browse latest View live


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