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

ContextAction MenuItem icon not showing in iOS

$
0
0

I'm developing PCL based solution using Xamarin.Forms. I added ContextAction to listview. I have delete MenuItem with trash icon in ContextActions. The trash icon not showing in iOS not platform.But in android its working fine. the iOS not support MenuItem icon?
My XAML code is

        <ViewCell.ContextActions>
                <MenuItem Text="Edit" x:Name="MenuEdit" />
                <MenuItem Clicked="OnDeleteMenu" Icon="dustbin.png" Text="Delete" IsDestructive="true" CommandParameter {Binding .}" />
    </ViewCell.ContextActions>

i am using latest Xamarin.Forms.Please Anyone give the solution

Thanks,
Mahabaleshwar Hegde


Select a value from a XML through URL

$
0
0

I want to bind a value from a XML file I'm getting online to my XAML-code do display the value in the app.

My application is pretty simple.

I use XDocument to read the xml-file with currency rates. I want to select the USD_Sell value that looks like this in the xml online.

The XML file online looks like this

<row>
<swift_code>USD</swift_code>
<swift_name>amerikanska Dollar</swift_name>
<multiply>1</multiply>
<buy_cash>8,5199</buy_cash>
<buy_tc>8,2643</buy_tc>
<sell_cash>9,3801</sell_cash>
<sell_tc>9,4739</sell_tc>
<CurrencyGuide BaseSwift="SEK" Swift="USD" Amount="100">10,66</CurrencyGuide>
<base_swift>SEK</base_swift>
</row>

My code so far only looks like this.

This is the main method which I'll be using. I'm just trying to get an basic understanding of Xamarin.Forms and using XML-documents online for data retrieval.

using Xamarin.Forms;
using System.Xml.Linq;

namespace CurrencyConverter
{
public partial class CurrencyConverterPage : ContentPage
{
    public CurrencyConverterPage()
    {
        InitializeComponent();
    }

    static void Main(string[] args)
    {
        XDocument xmlDoc = XDocument.Load("http://www.forex.se/ratesxml.asp? id=492");

    }

  }
}

And the XAML looks like this.

<Label  Text="USD Sell"
       TextColor="Black"
       Font="Medium"
       HorizontalOptions="Center"/>

<Label  Text="{Binding USDSell}"
       TextColor="Black"
       Font="Medium"
       HorizontalOptions="Center"/>

I just want to get the USD_Sell value to my label in the XAML

Is that any way to use custom fonts in xamarin forms and get output in all platform?

$
0
0

better in xaml file and use font family attribute

Messaging center unsubscribe from all messages when broadcast stops?

$
0
0

I was wondering... in my Xamarin Forms app when I leave a form I may be back so I do not unsubscribe from messages I just Ignore them...
But, after the user navigates back to a certain location I want to unsubscribe from all messages that had been being sent by a process so how would I do that ?
An example of this would be while the user is performing some action we would start listening for the location of the device and sending it to forms...
When they go back to another section, say taking notes about the overall process we would stop listening for location and would like to clear the messaging center queue to keep it clean ......

Snippet time: Simple ListView replacement

$
0
0

Hi all

I've struggled with the Xamarin Forms ListView on both Android and iOS for a while now. It doesn't render a correct height if in a vertical StackLayout, rendering is choppy even with just a few items (with or without virtualization), scrolling up/down messed up the template rendering etc.

All my lists are rather small - a few items, at one point maybe 10-20 items, that's it. In the end, a very simple control that just renders all items in a dynamically created grid solved all my problems. In case you're interested:

https://gist.github.com/hardcodet/338287c19df14982849733ea9732582d

Here's a sample on how I use it:

<ScrollView VerticalOptions="FillAndExpand"
            InputTransparent="{Binding IsRefreshingRides}">

    <controls:ItemsGrid ItemTapCommand="{Binding GoToRideCommand}"
                        ItemTemplate="{StaticResource RideCardTemplate}"
                        Items="{Binding UserRides}" />

</ScrollView>

The order here matters - since that was purely internal, I didn't care about coercing the properties (I probably will at another time).
However, this renders nicely in a vertical StackLayout with a button pinned to the bottom. Here's that list with three items:

I'm still very new to Xamarin - in WPF land, I would have started with an ItemsControl rather than this, and I thinks theres corresponding classes in Xamarin land too. But in the end, I just wanted to get the job done (and am hoping that I can throw this away one day and go back to ListView). For now though, any improvements/suggestions welcome! PullToRefresh definitely would be a nice addition, for example.

Cheers,
Philipp

Gradient background (vertical) custom renderer for Windows Phone and UWP

$
0
0

Hello, I need to write a custom renderer for WP and UWP to obtain a linear vertical gradient background color for a ContentPage. I already wrote the renderers for iOS and Android, need some help on how to do this for the windows side.

Thanks in advance!

Xamarin Forms Previewer Not working only showing blue blank screen

$
0
0

Anybody knows why ? It did not give me any errors; it is just not working.

Please help :)

XF + Azure Mobile App + Offline Sync

$
0
0

Appreciate any help regarding issue in my XF + Azure Mobile App + Offline Sync.
Common Startup Flow A:
1.) Create azure service objects (MobileServiceClient)
2.) Create db store objects (MobileServiceSQLiteStore)
3.) Register entity to sqlite table via DefineTable()
4.) MobileServiceClient.SyncContext.InitializeAsync()
5.) Check for cached auth token

Branch Flow B : Invalid/No Token found (First launch)
6.) Display login page (XF)
7.) Perform custom authentication via MobileServiceClient.InvokeApiAsync()
8.) Extract GWT auth token from response (failed scenario is omitted here)
9.) Cache auth token for future usage (with token expiry info)

Branch Flow C : Valid Token found (Subsequent launch)
10.) Create azure service user from token (MobileServiceUser)
11.) Associate user to azure service object
MobileServiceClient.CurrentUser =
MobileServiceClient.CurrentUser.MobileServiceAuthenticationToken =
12.) Perform synchronisation
MobileServiceClient.SyncContext.PushAsync()
MobileServiceClient.GetSyncTable().PullAsync()

My problem is, when i do flow A->B->C, my synchronisation is not returning from PushAsync().
Once I force closed my app and re-launch into flow A->C, everything will work properly (PushAsync() completes and PullSync() retrieve data from remote).
I also tried to remove the "redundant" PushAsync() in step #12, but still face the same issue where synchronisation became not returning from PullAsync().


Chat message, hide keyboard not fire send button click event

$
0
0

HI, i'm developing xamarin forms application. I want to develop a chat like whatsapp. All my view are done and in order to make visible textview where to write message, i've created a custom view renderer that on keyboard show, resize view. This thing work well, but the problem is when i tap send button that is aside text input, keyboard hide and the event click is not fired. If i tap send button when keyboard is hide, click event is fired.
This happen olny in ios, in android all works well.
This is my page renderer code

public class ChatPageRenderer : ViewRenderer<ContentView, UIView>
{
NSObject observerHideKeyboard;
NSObject observerShowKeyboard;

    protected override void OnElementChanged(ElementChangedEventArgs<ContentView> e)
    {
        observerHideKeyboard = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillHideNotification, OnKeyboardNotification);
        observerShowKeyboard = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillShowNotification, OnKeyboardNotification);
        base.OnElementChanged(e);


    }

    protected override void Dispose(bool disposing)
    {
        NSNotificationCenter.DefaultCenter.RemoveObserver(observerHideKeyboard);
        NSNotificationCenter.DefaultCenter.RemoveObserver(observerShowKeyboard);
        base.Dispose(disposing);
    }

    // DA RIVEDERE PERCHè NON SI INVIA IL MESSAGGIO CON TASTIERA APERTA
    void OnKeyboardNotification(NSNotification notification)
    {

        // Resize view bounds
        var frameBegin = UIKeyboard.FrameBeginFromNotification(notification);
        var frameEnd = UIKeyboard.FrameEndFromNotification(notification);


        var visible = notification.Name == UIKeyboard.WillShowNotification;

        if (visible)
            (Element as ContentView).Padding = new Thickness((Element as ContentView).Padding.Left, (Element as ContentView).Padding.Top, (Element as ContentView).Padding.Right, (Element as ContentView).Padding.Bottom + frameBegin.Height);
        else
            (Element as ContentView).Padding = new Thickness((Element as ContentView).Padding.Left, (Element as ContentView).Padding.Top, (Element as ContentView).Padding.Right, 0);

        //var newBounds = new Xamarin.Forms.Rectangle((float)oldbounds.Left, (float)oldbounds.Top, (float)oldbounds.Width, (float)(oldbounds.Height - frameBegin.Top + frameEnd.Top));
        //Element.Layout(newBounds);

    }

}

Xamarin.Forms Feature Roadmap

$
0
0

This roadmap outlines our anticipated feature releases.

Are there things you don't see here that you feel strongly deserve a spot? Make your voice heard and open a proposal on the Xamarin.Forms Evolution forum.

Primary Focus

Quality is top of the list. This means stability and performance first and foremost. Xamarin.Forms has been swiftly adopted as a preferred tool for delivering production apps in addition to rapid prototypes. Our focus and priorities are to support the Xamarin.Forms community in those areas. In the release schedule below, we've highlighted how and where we are making those investments.

A Note About Bugs

As this thread is primarily about the feature roadmap, we anticipate the important question "what about ___ bug"?! Improving quality by addressing bugs is huge priority and ongoing focus for the team, in addition to improve our communication across the board.

Disclaimer

We cannot predict the future and how everything will shake out. Things will change. Timing may be adjusted due to priority changes, in pursuit of quality standards, or any number of other really good reasons that we will strive to proactively and openly communicate.

The Features Roadmap

Milestone Release Date
2.3.3 December 2016
2.4.0 February 2017
2.5.0 May 2017

2.3.3 - December 2016

Native View Declaration - Feature
Native view declaration allows you to add bindable iOS, Android, and Windows views directly to XAML. Rather than having to write a custom renderer, you can simply add the control directly to XAML with no additional configuration. This not only works with stock platform controls, but custom controls as well.

Platform-Specifics - Feature
Platform-specifics allow you to take advantage of native functionality that is only available on select platforms that Xamarin.Forms targets from shared code.

UWP Blur Support (3rd party nuget) - Feature
Adds the UWP blur platform-specific.

2.4.0 - February 2017

Bindable Picker - Feature
Adds data binding to the Picker control, specifically the following properties:

  • ItemSource

  • SelectedItem

https://github.com/xamarin/Xamarin.Forms/pull/515

Accessibility (A11y) Support - Feature
Proposal
Adds accessibility support to Xamarin.Forms by exposing the underlying accessibility features on iOS, Android, and Windows 10.

CarouselView v1 Stable - Feature
CarouselView was introduced at Xamarin Evolve 2016 and has been in prerelease ever since. v1 brings stability and performance improvements.

Xamarin.Forms for macOS Preview - Feature
Xamarin.Forms is coming to macOS, joining iOS, Android, Windows, and Tizen as target platforms for Xamarin.Forms.

Fast Renderers - Performance
Optimize built-in and custom view renderers to streamline view creation and improve performance.

Startup Time Improvements - Performance
Improve the startup and initialization time for Xamarin.Forms apps.

Compiled Native Views - Enhancement, Performance
Bring native view declaration to XAMLC, so users don't have to opt-out of XAMLC in PCLs where pages use native view declaration.

OnIdiom Support for Desktop (UWP) - Enhancement
Developers have lots of options when it comes to configurability based on operating system (Android, iOS, UWP, etc.), version (9, 10, etc.), and idiom (mobile or tablet). This adds Desktop as an OnIdiom for UWP developers.

https://github.com/xamarin/Xamarin.Forms/pull/420

XAMLC Enhancements - Enhancement, Performance
Approaching full support for currently supported XAML features. Compile time support for all value providers.

Deprecation of iOS 6/7

Deprecation of WP8

2.5.0 - May 2017

Xamarin.Forms Embedding - Feature
Embed Xamarin.Forms into a native Xamarin.iOS, Xamarin.Android, or Windows 10 app.

Xamarin.Forms for macOS - Feature
Xamarin.Forms is coming to macOS, joining iOS, Android, Windows, and Tizen as target platforms for Xamarin.Forms.

MenuPage - Feature
Alternative to the MasterDetail page, but rendered as a platform-specific menu that makes creating flyouts easy.

Cut down on GPU overdraw for Android - Performance
Try to avoid overdraw on Android where possible to improve performance.

Reduce native views created - Performance
Cut down on backing native views created for Xamarin.Forms, as noted by Miguel in #42948.

Layout Compression - Performance
LayoutCompression allows multiple layers of Xamarin.Forms layouts to be packed into a single native one.

Prism-Like URI Navigation Routing - Enhancement
Navigate to a page using Uri navigation, similar to what Prism does.

NavigationService.NavigateAsync("ListPage/DetailPage?id=1");

Single DLL - Enhancement
Ship Xamarin.Forms as a single DLL to improve startup performance and assist the linker.

Open Source Contributions

As noted above, the Xamarin.Forms Evolution forum is the place to start.

Scroll to input when focusing on another input.

$
0
0

How can I do that when you enter in the field the page scrolls so that you can see the box below? Otherwise, every time they leave the entry mode to select the next field.

Is it possible to remove a bound label if it is empty?

$
0
0

I have a program that generates a list of StackLayouts with nested layouts/objects, and one of the objects is a Label that may or may not contain text. In my ViewCell, I set the default text to "", but it's included in the layout. In my ContentPage, I create a dummy list to test, and if I don't change that Label, it still takes up space and looks awkward. Is there any way to remove the label if it's empty (if == "")?

ViewCell:

Label Description = new Label();
            Description.Text = "";
            Description.SetBinding(Label.TextProperty, "description");

Data Class:

public class dataClass
            {
                    public string description { get; set; }
            }

ContentPage:
`List itemList = new List();

        var entry1 = new dataClass() {
                ...
                description = "hello",
                ...
        }
        itemList.Add(entry1);

        var entry2 = new dataClass() { // don't change the description so it's left as ""
                ...
                ...
        }
        itemList.Add(entry2);

        ListView itemListView = new ListView();
        itemListView.ItemsSource = itemList;
        itemListView.ItemTemplate = new DataTemplate(typeof(EventsEntry));`

So in this case, entry2 has an empty Label but still takes up as much space as the Label in entry1. I would prefer to have that Label not exist if it stays empty.

iOS comma as a Decimal separator

$
0
0

We have a multi-lingual app which supports two culture English and Arabic.

I am facing an issue where I have a Numeric keyboard and it displays comma as a Decimal point when device language or region is set to any European country (e.g Spanish (en-ES)) even though I enforce locale in my app to English (en-US).

This seems to be iOS device issue and I somehow can't override the Keyboard (as far as I know) to change comma to Decimal point (".").

I have tried below mentioned solutions in my iOS custom tenderer which haven't worked so far.
1. Formatting comma on text changed event. FYI, I have mentioned one of the way below.
NSNumberFormatter formatter = new NSNumberFormatter();
formatter.DecimalSeparator = ",";
Control.Text = formatter.NumberFromString(Control.Text).ToString();

  1. Adding "." to UIKeyboardType NumberPad. Problem I am having with this one is TouchUpInside event is not being called.
    private UIButton _doneButton;
    _doneButton = new UIButton(UIButtonType.Custom);
    _doneButton.Frame = new RectangleF(0, 163, 106, 53);
    _doneButton.SetTitle(".", UIControlState.Normal);
    _doneButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
    _doneButton.SetTitleColor(UIColor.White, UIControlState.Highlighted);
    _doneButton.AddTarget(handler, UIControlEvent.TouchUpInside);
    _doneButton.AddTarget((sender, arg)=> { Control.Text += "."; }, UIControlEvent.TouchDown | UIControlEvent.TouchCancel);
    _doneButton.TouchUpInside += (sender, arg) =>
    {
    Control.Text += ".";
    };
    this.Control.KeyboardType = UIKeyboardType.AsciiCapableNumberPad;
    NSString s = NSString.FromData(NSData.FromString("UIKeyboardWillShowNotification"), NSStringEncoding.UTF8);
    NSString h = NSString.FromData(NSData.FromString("UIKeyboardWillHideNotification"), NSStringEncoding.UTF8);
    NSNotificationCenter.DefaultCenter.AddObserver(s, KeyboardWillShow);
    NSNotificationCenter.DefaultCenter.AddObserver(h, KeyboardWillHide);

public void KeyboardWillHide(NSNotification notification)
{
var shared = UIApplication.SharedApplication;
_doneButton.Hidden = true;
}

public void KeyboardWillShow(NSNotification notification)
{
var shared = UIApplication.SharedApplication;

var keyboard = Control.WeakInputDelegate as UIView;
if (keyboard != null)
{
    _doneButton.Hidden = false;
    keyboard.AddSubview(_doneButton);
    keyboard.BringSubviewToFront(_doneButton);
}

}

  1. I tried creating custom keyboard but couldn't, and I believe there are no plugins for Xamarin.Forms that I can use. Limitation of Xamarin.Forms?

The solution that we are looking for is when we enforce the culture in app to en-US it should always show a numeric keyboard with decimal point (".") which can be a custom keyboard, and when in future we start supporting spanish language we would like to do the formatting of comma to decimal point before sending the request to database.

Thanks in advance :smile:

Xamarin.Forms.GoogleMaps Shows green screen on emulator

$
0
0

hi,
i am trying to use Xamarin.Forms.GoogleMaps nuget in a xamarin.forms project but all i get is a green screen with "Xamarin.Forms.GoogleMaps" text in the middle on my emulator

this is the app.cs

    public App()
        {
            // The root page of your application
            var content = new ContentPage
            {
                Title = "GoogleTestApps",
                Content = new StackLayout
                {
                    VerticalOptions = LayoutOptions.FillAndExpand,
                    Children = {
                        new Map(MapSpan.FromCenterAndRadius(new Position(30.0444, 31.2357), new Distance(200))) {
                            VerticalOptions = LayoutOptions.StartAndExpand,
                            HorizontalOptions = LayoutOptions.FillAndExpand,
                            HeightRequest = 920,
                            WidthRequest = 400,
                            MapType = MapType.Street
                        }
                    }
                }
            };

            MainPage = new NavigationPage(content);
        }

and this is my AndroidManifest file

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
  <uses-sdk android:minSdkVersion="15" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
  <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  <uses-permission android:name="android.permission.INTERNET" />
  <application android:label="GoogleTestApps.Droid">
    <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="Key" />
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
  </application>
</manifest>

this is what is shown on the emulator

How To Get Horizontal List View With Navigation?

$
0
0

how to get horizontal listview that navigates to other page.


How to Navigate Each Row in ListView To Another page

$
0
0

Similar to contacts list in our phone. how to do it in xamarin ?

Binding a collection to a listview in the code behind using Data Template Selector

$
0
0

I'm in the process of switching all of my apps UI from Xaml to the code behind. But I am having some trouble getting binding to work with a list view. Here is my scenario:

mypage.xaml.cs:

ListView listView = new ListView()
{
    ItemsSource = _chatViewModel.ChatMessageCollection, // contains a collection of ChatMessage objects
    ItemTemplate = new ChatMessageTemplateSelector()
};

ChatMessageTemplateSelector.cs (I'll show show one of the properties):

private DataTemplate IncomingMessageTemplate
{
    get
    {
        DataTemplate dt = new Datatemplate();
        ...
        Label label = new Label()
        {
            Text = // Here is the problem
        };
        ...
        return dt;
    }
}

I'm stuck at trying to figure out how to set the Label's Text property to the ListView's ItemsSource's ChatMessage.Body property. I think I have to use the SetBinding() function, but I'm just not sure where to go next from here. Any help would be appreciated

Button BorderColor not showing on Android 4.4

$
0
0

The title says it all. My code can be seen below.

    Button mybtt = new Button
        {
            BorderColor = Color.Black,
            BackgroundColor = Color.Transparent,
            IsEnabled = true,
            BorderWidth = 1,
            BorderRadius = 0,
        };

Can someone confirm the issue? There is a way around this problem?

Problem with Button Clicked. BLE.Plugin

$
0
0

Hi! I have this following code. The problem is that when I put the code outside the ButtonScan method, it works. If I put it inside the method, it doesn't work because it doesn'tt let me click on the button. I'm working with BLE.Plugin.

MainPage.xaml

<StackLayout Padding="10,10,10,10" BackgroundColor="White">
  <Image TranslationY="20" Source="Image.png"/>
  <Button x:Name="btn_scan_device" BorderColor="Black" Text="Scan" TextColor="Green" TranslationY="150" WidthRequest="60"   HeightRequest="50" Clicked="ButtonScan"/>
  <StackLayout x:Name="sl_deviceList">
    <ListView x:Name="lv_deviceList">
      <Label x:Name="lbl_deviceList" />
    </ListView>
  </StackLayout>
</StackLayout>

MainPage.xaml.cs (This Works)

public partial class MainPage : ContentPage
{
    public IDevice device;

    public MainPage()
    {
        InitializeComponent();

        var ble = CrossBluetoothLE.Current;
        var adapter = CrossBluetoothLE.Current.Adapter;

        ble.StateChanged += (s, c) =>
        {
            Debug.WriteLine($"The bluetooth state changed to {c.NewState}");
        };

        adapter.DeviceDiscovered += (s, a) =>
        {
            Debug.WriteLine($"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!NEW DEVICE FONDUURUUUUUUUU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! {a.Device.Name}");
        };

        adapter.StartScanningForDevicesAsync();

    }

    public void ButtonScan(object sender, EventArgs e)
    {

    }
}

(This NOT Works)

public partial class MainPage : ContentPage
{
    public IDevice device;

    public MainPage()
    {
        InitializeComponent();

    }

    public void ButtonScan(object sender, EventArgs e)
    {
        var ble = CrossBluetoothLE.Current;
        var adapter = CrossBluetoothLE.Current.Adapter;

        ble.StateChanged += (s, c) =>
        {
            Debug.WriteLine($"The bluetooth state changed to {c.NewState}");
        };

        adapter.DeviceDiscovered += (s, a) =>
        {
            Debug.WriteLine($"!!!!!!!!!!!!!!!!!!!!!!!!!!NEW DEVICE FONDUURUUUUUUUU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! {a.Device.Name}");
        };

        adapter.StartScanningForDevicesAsync();
    }
}

PRISM: Sending messages between App.xaml.cs and the current view

$
0
0

I need to send a message from App's OnResume and OnSleep methods to the current view using PRISM. Does anyone know if this is possible with EventAggregator? I've seen examples on how to use the aggregator between viewmodels, but I'm not sure if it can be used between App.xaml.cs and the current view.

Viewing all 91519 articles
Browse latest View live


Latest Images

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