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

Unexpected behavior when selecting listview items with changed background color only on iOS

$
0
0

Dear all,

I'm currently developing an app with Xamarin.Forms where i got an very strange behavior when I select listview items.
One feature of this app should be a view cell with a non default background color when selected.

I tried many ways (*not tested on a real apple device): dataTriggers, stackLayout with backgroundColor binding, custom viewCells

The last one successed on android but on iOS the following is happening:
Example: 3 Items ('1', '2', '3')

Select: 1

  • Nothing happens
  • Select: 3

  • 1 Selected

Select: 2

  • 3 Selected

so on .....

Code:

  [assembly: ExportRenderer(typeof(ExtendedViewCell), typeof(ExtendedViewCellRenderer))]
  namespace IOS
  public class ExtendedViewCellRenderer : ViewCellRenderer
  {
       public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
       {
            var cell = base.GetCell(item, reusableCell, tv);
            var view = item as ExtendedViewCell;
            cell.SelectedBackgroundView = new UIView
            {
                    BackgroundColor = view.SelectedBackgroundColor.ToUIColor(),
             };

           return cell;
      } 


 [assembly: ExportRenderer(typeof(ExtendedViewCell), typeof(ExtendedViewCellRenderer))]
 namespace Android
 {
   public class ExtendedViewCellRenderer : ViewCellRenderer
   {

     private Android.Views.View _cellCore;
     private Drawable _unselectedBackground;
     private bool _selected;

     protected override Android.Views.View GetCellCore(Cell item, Android.Views.View convertView, ViewGroup parent, Context context)
     {
       _cellCore = base.GetCellCore(item, convertView, parent, context);
       _selected = false;
       _unselectedBackground = _cellCore.Background;
       return _cellCore;
     }

     protected override void OnCellPropertyChanged(object sender, PropertyChangedEventArgs args)
     {
       base.OnCellPropertyChanged(sender, args);

       if (args.PropertyName == "IsSelected")
       {
         _selected = !_selected;

         if (_selected)
         {
              var extendedViewCell = sender as ExtendedViewCell;
             _cellCore.SetBackgroundColor(extendedViewCell.SelectedBackgroundColor.ToAndroid());
         }
        else            _cellCore.SetBackground(_unselectedBackground);
       }
     }
   }
}


public class ExtendedViewCell : ViewCell
{
        public static readonly BindableProperty SelectedBackgroundColorProperty = BindableProperty.Create("SelectedBackgroundColor", typeof(Color), typeof(ExtendedViewCell), Color.Default);

    public Color SelectedBackgroundColor
        {
            get { return (Color)GetValue(SelectedBackgroundColorProperty); }
            set { SetValue(SelectedBackgroundColorProperty, value); }
        }
}

<ListView VerticalOptions="FillAndExpand"  HorizontalOptions="FillAndExpand"  BackgroundColor="Black"  ItemsSource="{Binding .}" RowHeight="52">
<ListView.ItemTemplate>
            <DataTemplate>
                <customControls:ExtendedViewCell SelectedBackgroundColor="Teal">
          <ViewCell.View>
            <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Orientation="Vertical" Padding="4" Spacing="8">
                <Label TextColor="White" Text="{Binding Name}"/>
            </StackLayout>
          </ViewCell.View>
        </customControls:ExtendedViewCell>
      </DataTemplate>
    </ListView.ItemTemplate>
  </ListView>

BindingContext = public ObservableCollection<Model> MyModels { get; set; }

Does anyone know whats wrong here?

All nuget versions are up to date.
Tried on iPhone 6s Plus, iPhone 8 Plus (Simulator).

Thank you


Xamarin Forms WebView and GestureRecognizers not working with android

$
0
0

Hello,

I have created a webview to load my local HTML file. My application requires to load another HTML file as the user swipes right or left. I have created this functionality with the following code:

    <WebView
        x:Name="HtmlView"
        Grid.Row="1" 
        Source="{Binding HTMLFile}" 
        HorizontalOptions="FillAndExpand" 
        VerticalOptions="FillAndExpand"
        GoBackRequested="Handle_GoBackRequested"
        GoForwardRequested="Handle_GoForwardRequested"
        >
        <WebView.GestureRecognizers>
        <SwipeGestureRecognizer Direction="Left" Swiped="Handle_SwipedLeft"/>
        <SwipeGestureRecognizer Direction="Right" Swiped="Handle_SwipedRight"/>
        </WebView.GestureRecognizers>
    </WebView>

And Implemented the handlers as shown below:

    void Handle_SwipedLeft(object sender, Xamarin.Forms.SwipedEventArgs e)
    {
        flashCard.HTMLFile = getHTMLFileFromDevice("FlashCard2.html");
        HtmlView.Reload();
    }

    void Handle_SwipedRight(object sender, Xamarin.Forms.SwipedEventArgs e)
    {
        flashCard.HTMLFile = getHTMLFileFromDevice("FlashCard3.html");
        HtmlView.Reload();
    }

This works completely fine with iOS, however if try running it on android (using the emulator) the handlers are not called at all. Is there something that I am missing here?

Thanks

Xamarin.Forms CardsView nuget package

$
0
0

Hi all) I've released new package for Xamarin.Forms (Something like Tinder's CardsView)
Maybe, someone will be interested in it

nuget.org/packages/CardsView/ -- nuget
github.com/AndreiMisiukevich/CardView -- source and samples

CarouselView implementation, CardsView nuget package

UWP ToolbarItem TextColor

$
0
0

Hi

I have a Xamarin.Forms app targeting iOS, Android and UWP. When I add some toolbaritems (secondary) and start the UWP on my Windows10 machine. The menu appears (when I cklick on the 3-dots-button), but the text is in white color.

This is because my ApplicationBar (with the title) has a blue background color and a white text.

I know, I can't change the color directly on the toolbaritem. But I thought about a renderer...

But how? Can anybody help me out?

My Renderer:

public class UwpBasePageRenderer : PageRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null || Element == null) return;

            Loaded += OnLoaded;
        }

        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            var mypanel = ContainerElement as Panel;

            // Something like this...
            // mypanel.ApplicationBar.TextColor = Black;

        }
    }

Apple rejected my Xamarin.Forms iOS App for usage of non-public API which I don't use

$
0
0

I have an App that is under development using Xamarin. Forms and I have submitted more than 40 beta until now and it works fine, randomly in the last week I have started getting rejected from App with the following error

The app references non-public selectors in Appname.iOS: addTemporaryAttribute:value:forCharacterRange:, addTemporaryAttributes:forCharacterRange:, behaviorWithType:, defaultBaselineOffsetForFont:, defaultLineHeightForFont:, finished, greekingThreshold, horizontalCornerRadius, initWithSource:convolutionState:weights:, initWithType:, postSession:didAddPlayer:, postSession:didReceiveData:fromPlayer:, postSession:didReceiveMessage:withData:fromPlayer:, postSession:didRemovePlayer:, postSession:player:didChangeConnectionState:, postSession:player:didSaveData:, preferredMetalContext, removeData:, removeTemporaryAttribute:forCharacterRange:, setGreekingThreshold:, setHorizontalCornerRadius:, setIsPrimary:, setShouldAntiAlias:, setUUID:, setVerticalCornerRadius:, shouldAntiAlias, temporaryAttribute:atCharacterIndex:effectiveRange:, temporaryAttribute:atCharacterIndex:longestEffectiveRange:inRange:, temporaryAttributesAtCharacterIndex:effectiveRange:, temporaryAttributesAtCharacterIndex:longestEffectiveRange:inRange:, textContainerChangedTextView:, toolTip, usesBackgroundSession, verticalCornerRadius

Also, I have seen a lot of issues since the last VS2019 for mac 2 weeks ago

I have found that several ppl got the same issue as the ones here, but neither solution solved my issue
Which I don't and don't understand the problem, I have already submitted an email without a reply until now, does anyone encounter the same issue?

Entry Custom Renderer Frame.Width is always 320

$
0
0

I'm writing a custom Entry class to have Entry controls on iOS only have an underline. In my custom renderer, the Frame.Width is always 320 no matter how wide I make the control. I draw the underline that size and the entry field is obviously longer because the typing goes beyond the end of the underline.

I'm doing the drawing in OnElementChanged. Should I be doing it somewhere else?

What am I doing wrong?

Period of Day Picker

$
0
0

Hi, could anyone point me in the right direction on how to create a period of day picker as depicted in the image? (Taken from Outlook app on Android)
At the moment I am using two TimePickers to select a start and end time, but would like something slicker.

Thanks!!


Xamarin Forms WebView and GestureRecognizers not working with android

$
0
0

Hello,

I have created a webview to load my local HTML file. My application requires to load another HTML file as the user swipes right or left. I have created this functionality with the following code:

    <WebView
        x:Name="HtmlView"
        Grid.Row="1" 
        Source="{Binding HTMLFile}" 
        HorizontalOptions="FillAndExpand" 
        VerticalOptions="FillAndExpand"
        GoBackRequested="Handle_GoBackRequested"
        GoForwardRequested="Handle_GoForwardRequested"
        >
        <WebView.GestureRecognizers>
        <SwipeGestureRecognizer Direction="Left" Swiped="Handle_SwipedLeft"/>
        <SwipeGestureRecognizer Direction="Right" Swiped="Handle_SwipedRight"/>
        </WebView.GestureRecognizers>
    </WebView>

And Implemented the handlers as shown below:

    void Handle_SwipedLeft(object sender, Xamarin.Forms.SwipedEventArgs e)
    {
        flashCard.HTMLFile = getHTMLFileFromDevice("FlashCard2.html");
        HtmlView.Reload();
    }

    void Handle_SwipedRight(object sender, Xamarin.Forms.SwipedEventArgs e)
    {
        flashCard.HTMLFile = getHTMLFileFromDevice("FlashCard3.html");
        HtmlView.Reload();
    }

This works completely fine with iOS, however if try running it on android (using the emulator) the handlers are not called at all. Is there something that I am missing here?

Thanks

Xamarin Forms: Load a contentpage when tap push notification android

$
0
0

I completed receiving test notification from FCM console. Now I am trying to open a page when tapping the notification. Any ideas about how to achieve this? I have searched the internet but can't find a working solution. I am also able to send the notification through the postman.

Trying to not update on page rotation

$
0
0

Hello!

Maybe this is a very basic question, but I can't find the right words combination in order to find an answer.
I have a page with its ViewModel. I'm using code behind to trigger a reloading command, from my VM, in the "OnAppearing" event, only if ViewModel.IsInitialized is true.
This way, when using navigation back and forth, I'm sure that the page's content is refreshed everytime I'm back to it.

But there's one problem: it triggers the reload command when I change from portrait to landscape or viceversa. How can I avoid that?
I wasn't able to find a list of Xamaring events... except for Xamaring events like meetings and speechs in real world ^^U

Also, it looks like it triggers too when I'm in a child or grand-child page. What I'm missing?

Custom Renderer for Span

$
0
0

Hello devs!

I'm trying to make a Custom Renderer to ignore the ****android**** accessibility configurations in the ****Span Class****, to ****not re-scale the font size****.
I have made successfully renderer for the Label class but not for Span class.. Can someone help me? :D

****My Label Custom Renderer is Above!****
<br /> using System;<br /> using System.ComponentModel;<br /> using Android.Widget;<br /> using FreePlay.Droid;<br /> using Xamarin.Forms;<br /> using Xamarin.Forms.Platform.Android;</p> <p>[assembly: ExportRenderer(typeof(Span), typeof(IgnoreAcessibilitySpan))]<br /> namespace FreePlay.Droid<br /> {</p> <pre><code>public class IgnoreAcessibilitySpan : LabelRenderer { protected void setFontSizeAgain() { var nativeControl = (TextView)Control; var xfControl = Element; //e.NewElement; if (nativeControl != null && xfControl != null) nativeControl.SetTextSize(Android.Util.ComplexUnitType.Dip, xfControl.Font.ToScaledPixel()); } protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Label> e) { base.OnElementChanged(e); setFontSizeAgain(); } protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); setFontSizeAgain(); } }

}

Xamarin forms - Can deploy to iPhone but not iPad (error code 0xe8008015)

$
0
0

I have a Xamarin Forms app that works well on Android and iPhone. But when I am trying to debug my Xamarin.Form application in iPad, it shows the following error. Can anybody please suggest?

error MT1006: Could not install the application
'/Users/iotg/Library/Caches/Xamarin/mtbs/builds/MyApp.iOS/976da0c08e8bb7065faabf8e70b7bd35/bin/iPhone/Debug/MyApp.iOS.app' on the device 'MyiPad': AMDeviceSecureInstallApplicationBundle returned: 0xe8008015.

Configuration
Visual Studio: Visual Studio Professional 2017 for Windows 10
Test Mode: Debug
Xcode:10.2.1
iOS: 12.2
iPad: iPad Pro 12.9

Thanks for your help.

Local reminder notifications

$
0
0

Hello I need help, I'm working on an application that has to control the day and time to deliver tasks. The logic of the application is as follows: the user must enter date and time to deliver his task, after this the application must show a local notification the day and time that the user entered, but still can not make that happen, could give me suggestions

FFImageLoading issue on iOS

$
0
0

Hi,

I am using FFImageLoading library in my Xamarin.forms project to display animated GIF splash screen. In android it is behaving as expected, but in iOS I am getting the below error. Please help if any of you have come across the same issue.

/Users/name/Documents/Code/: Error MT2101: Can't resolve the reference 'System.Void SkiaSharp.SKPath::AddRoundRect(SkiaSharp.SKRect,System.Single,System.Single,SkiaSharp.SKPathDirection)', referenced from the method 'SkiaSharp.SKPath FFImageLoading.Svg.Platform.SKSvg::ReadElement(System.Xml.Linq.XElement,System.Collections.Generic.Dictionary`2<System.String,System.String>)' in 'SkiaSharp, Version=1.68.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756'. (MT2101)

Thanks in advance,


standard C# samples for Xamarin.Forms

$
0
0

https://developer.xamarin.com/samples/xamarin-forms/all/

The Microsoft Xamarin official website only has samples for how to use the UI.
In fact, most standard C# foundation can be used to Xamarin.Forms, just like the Socket.
But there is no samples for them.

Maybe there has some samples for use standard C# foundation in Xamarin.Forms, just I am not found.
Is there any official website for it?

Terminate Xamarin Forms App | Quitting Xamarin Forms App

$
0
0

Is there any other better way to terminate Xamarin Forms App ? Than this ?

In Main Project PCL

MainPage.Xaml.cs(The Page Where i want to Terminate)

    protected override bool OnBackButtonPressed()
            {
                Device.BeginInvokeOnMainThread(async () =>
                {
                    var result = await this.DisplayAlert("Alert!", "want to exit?", "Yes", "No");
                    if (result)
                    {
                      var closer = DependencyService.Get<ICloseApplication>();
                      closer?.closeApplication();
                    }
                });
                return true;
            }

Interface

         public interface ICloseApplication
            {
                void closeApplication();
            }

Android

  [assembly: Xamarin.Forms.Dependency(typeof(CloseApplication))]
namespace XForms.Droid
{
    public class CloseApplication : ICloseApplication
    {
        public void closeApplication()
        {
            Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
        }
    }
}

IOS

 [assembly: Xamarin.Forms.Dependency(typeof(CloseApplication))]
namespace XForms.Droid
{
         public class CloseApplication : ICloseApplication
                {
                    public void closeApplication()
                    {
                        Thread.CurrentThread.Abort();
                    }
                }
        }

List View not listens to XAML but Sized as number of initial itemssource.

$
0
0

I have listview. It's Vertical and Horizontal Options are fill in Xaml.
I am setting it's source as somelist in OnAppearing Window.
protected override void OnAppearing() { base.OnAppearing(); ((ListView)FindByName("attributesList")).ItemsSource = d.attributes; }
Listview will size itself as number of items in attributes. If two list view will be size of two rows. If something added it scrolls but size is of only two rows. If initially there is no item. Nothing is shown. If I comment this Itemssource line, The list will expand on whole page as needed.

How to get data instantly from a api?

$
0
0

I am using newtonsoft to get json data like
HttpClient client = new HttpClient();
var response = await client.GetStringAsync("http:................");
var items = JsonConvert.DeserializeObject<List>(response);

But it take too much time to show in a list view as there are only 3000++ data.
It take much time for searching also . how can i improve the search and getting data quickly ?

How can I create and auto-start a service app, just after installation without launching it?

$
0
0

I want to create and auto-start a background service app just after it is installed from the play store, without launching it. The purpose to the service app is to initialise a centralised local database that needs to be accessed and modify by two other Xamarin apps. How can I achieve this?

Viewing all 77050 articles
Browse latest View live


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