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

Need to put HTML into a Label

$
0
0

I am using Xamarin.Forms and the Label view. I use the FormattedText (FormattedString class) to put formatted text in the Label. My goal here is to be able to convert HTML to a FormattedString.

In Xamarin.Android I have acces to Html.FromHtml() wich returns a ISpanned. Is there a equivalent for Xamarin.Forms ?

I cannot really use a WebView since my goal is to have multiple labels populated from HTML. If I use a WebView, I would be forced to do the whole page in HTML and not use Xamarin.Forms views/controls.

Thanks,
Max.


HTML in labels?

$
0
0

Is it possible to render HTML (simple tags and entities) in a Xamarin Forms Label?

Rendering label with HTML markup, is it possible?

$
0
0

Hi,

I am getting a data from JSON having article body content that has paragraphs (separated by C# style \r\n). This works well, however now the requirement is if body has bold () or italic tags (). It should recognize the same and render the way it is..

Is it possible to achieve the same?

Mix Normal, Decorated & Extended Text In a Label

$
0
0

Hello

Is it possible to have bold and non-bold text within a Xamarin.Forms Label widget? Is it possible to have endlines inside a Label aswell?

<Label Text="Abc <b>def</b>"/>
<Label Text="Abc \ndef"/>

How to display HTML hex code in label?

$
0
0

I want to display html hex code in label, for example ₹ - which is currency code for Rupee.

This works if I put it hardcoded in XAML, but won't work with dynamic text.

html formatting text to put on a label ,

$
0
0

html formatting text to put on a label ,

I have a htm tag my html </ b> and need to format to put on a label anyone know how to do?

What is the appropriate way to store a CookieContainer to persist throughout app lifecycle?

$
0
0

I'll preface this question with I'm new to C# and Xamarin, and working on my first Xamarin Forms app, targeting iOS and Android.

The app is using HttpClient to pass requests to an api, and the headers in the response return session cookies that are used to identify the current user. So once I've received an initial response and those cookies have been stored in the CookieContainer, I want to store that CookieContainer in some global scope so it can be reused and passed with all subsequent requests.

I've read that attempting to serialize the cookies data can be problematic, and HttpOnly cookies are included in the response, which I apparently can't access in the CookieContainer. Because of this, I've also tried enumerating through the values returned in the Set-Cookie header and storing it as a comma delimited string, then using SetCookies on the CookieContainer with that string for subsequent requests. But that seems overly complex and trying to do so results in a consistent, vague error "Operation is not valid due to the current state of the object." when requests are made. So I'm hoping to simply reuse the entire CookieContainer object.

So more pointedly, my questions are:

  1. Where is an appropriate place to store a CookieContainer object so that it will persist throughout the app's lifecycle, and preferably still be available when the app goes into the background and is resumed. Is simply declaring it as a static variable in my WebServices class good enough?

  2. If I do reuse the CookieContainer in this way, will the individual cookies be automatically updated on subsequent requests if more are added or the values of existing ones sent by the server change?

Here's a snippet from the method we're currently using (excluding my attempts at parsing the cookies into a string, which hopefully is unnecessary):

HttpResponseMessage httpResponse;

var cookieContainer = new CookieContainer (); // want to set/store this globally
var baseAddress = new Uri("http://www.test.com");

using (var handler = new HttpClientHandler () { CookieContainer = cookieContainer })
using (HttpClient client = new HttpClient (handler) { BaseAddress = baseAddress })
{
    // has a timeout been set on this Web Service instance? 
    if (TimeoutSeconds > 0) {
        client.Timeout = new System.TimeSpan(0,0,TimeoutSeconds);
    }

    // Make request (the "uri" var is passed with the method call)
    httpResponse = await client.GetAsync (uri);
}

Xamarin.Forms IOS Value cannot be null. Parameter name: key

$
0
0

Hi,

I cant figure this out:

I don't know if this is the correct aproach, neither the arquitecture. But works on android and let me create pages with less code.

I have what i called 'BaseQueryPage', this inherit from ContentPage.

Inside BaseQueryPage I have this code:

 internal virtual void UpdateLayout(T data)
                {
                    try
                    {
                        if (string.IsNullOrEmpty(data.Error))
                        {
                            DateLabel.Text = GetHttpResponseMessage(data);
                            var layout = new StackLayout()
                            {
                                Padding = new Thickness(5, 0),
                                Children =
                            {
                                CreateTitle(App.StockAccountNumber),
                                //CreateHeader(data),
                                new ScrollView()
                                {
                                    Content = CreateView(data),
                                     VerticalOptions = LayoutOptions.Fill,
                                },
                              //  CreateFooter(data),
                                new StackLayout()
                                {
                                    Orientation = StackOrientation.Horizontal,
                                    HorizontalOptions = LayoutOptions.Fill,
                                    Children =
                                    {
                                        DateLabel,
                                        RefreshButton,
                                        this.FormActivityIndicator
                                    }
                                },
                                ErrorLabel

                            }
                            };
                            Content = layout; // <- This Line pop ups the error

                        }
                        SetErrorMessage(data.Error);
                    }
                    catch (Exception ex)
                    {
                        var a = ex;
                    }

                }

whenever i call any of these methods:
CreateView();
CreateFooter();
CreateHeader();

I get the title error:

Lets, take any of these Functions:

      internal virtual View CreateHeader(T data)
            {
                return null;
            }

On the Actual View:

   internal override View CreateHeader(AccountBriefModel acountBrief)
        {

            var grid = new Grid
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                MinimumHeightRequest = 15,
                RowSpacing = 0,
                ColumnSpacing = 0,
                Padding = new Thickness(2)
            };

            grid.Children.Add(CreateLabel("Ticker", TextAlignment.Start, false, Color.White, Color.FromHex(SysVar.GetUI("headerColor"))), 0, 2, 0, 1);
            grid.Children.Add(CreateLabel("Precio", TextAlignment.End, false, Color.White, Color.FromHex(SysVar.GetUI("headerColor"))), 2, 4, 0, 1);
            grid.Children.Add(CreateLabel("Cantidad", TextAlignment.End, false, Color.White, Color.FromHex(SysVar.GetUI("headerColor"))), 4, 6, 0, 1);
            grid.Children.Add(CreateLabel("Monto", TextAlignment.End, false, Color.White, Color.FromHex(SysVar.GetUI("headerColor"))), 6, 9, 0, 1);



            var ly = new StackLayout()
            {
                Orientation = StackOrientation.Vertical,
                HorizontalOptions = LayoutOptions.Fill,
                Children = { grid }
            };

            return ly;
        }

I don't know what I am doing wrong...

The function returns everything ok.

Thanks!

(SstackTrace: " at System.ThrowHelper.ThrowArgumentNullException (ExceptionArgument argument) [0x00000] in /Users/builder/data/lanes/3051/5f11db87/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/throwhelper.cs:82
at System.Collections.Generic.Dictionary

2[TKey,TValue].FindEntry (System.Collections.Generic.TKey key) [0x0000b] in /Users/builder/data/lanes/3051/5f11db87/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/collections/generic/dictionary.cs:292 
  at System.Collections.Generic.Dictionary
2[TKey,TValue].ContainsKey (System.Collections.Generic.TKey key) [0x00000] in /Users/builder/data/lanes/3051/5f11db87/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/collections/generic/dictionary.cs:221
at Xamarin.Forms.Platform.iOS.EventTracker.LoadRecognizers () [0x0001e] in :0
at Xamarin.Forms.Platform.iOS.EventTracker.OnElementChanged (System.Object sender, Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs e) [0x0004e] in :0
at Xamarin.Forms.Platform.iOS.EventTracker.LoadEvents (UIKit.UIView handler) [0x0004e] in :0
at Xamarin.Forms.Platform.iOS.VisualElementRenderer
1[TElement].SetElement (Xamarin.Forms.Platform.iOS.TElement element) [0x000f3] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer
1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in :0
at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001b] in :0
at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x00000] in :0
at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x00023] in :0
at Xamarin.Forms.Platform.iOS.VisualElementRenderer
1[TElement].SetElement (Xamarin.Forms.Platform.iOS.TElement element) [0x000cc] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer
1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in :0
at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001b] in :0
at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x00000] in :0
at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x00023] in :0
at Xamarin.Forms.Platform.iOS.ScrollViewRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x0008e] in :0
at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001b] in :0
at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x00000] in :0
at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x00023] in :0
at Xamarin.Forms.Platform.iOS.VisualElementRenderer
1[TElement].SetElement (Xamarin.Forms.Platform.iOS.TElement element) [0x000cc] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer
1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in :0
at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001b] in :0
at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x00000] in :0
at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (System.Object sender, Xamarin.Forms.ElementEventArgs e) [0x0000f] in :0
at Xamarin.Forms.Element.OnChildAdded (Xamarin.Forms.Element child) [0x00037] in :0
at Xamarin.Forms.VisualElement.OnChildAdded (Xamarin.Forms.Element child) [0x00000] in :0
at Xamarin.Forms.Page.OnInternalAdded (Xamarin.Forms.VisualElement view) [0x00013] in :0
at Xamarin.Forms.Page.InternalChildrenOnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0005f] in :0
at System.Collections.ObjectModel.ObservableCollection
1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00012] in /Users/builder/data/lanes/3051/5f11db87/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:286 
  at System.Collections.ObjectModel.ObservableCollection
1[T].OnCollectionChanged (NotifyCollectionChangedAction action, System.Object item, Int32 index) [0x00000] in /Users/builder/data/lanes/3051/5f11db87/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:349
at System.Collections.ObjectModel.ObservableCollection
1[T].InsertItem (Int32 index, System.Collections.ObjectModel.T item) [0x00024] in /Users/builder/data/lanes/3051/5f11db87/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:217 
  at System.Collections.ObjectModel.Collection
1[T].Add (System.Collections.ObjectModel.T item) [0x00023] in /Users/builder/data/lanes/3051/5f11db87/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/collections/objectmodel/collection.cs:76
at Xamarin.Forms.ContentPage.set_Content (Xamarin.Forms.View value) [0x00044] in :0
at Gallo.Mobile.UI.BaseHelpers.BaseQueryPage`1[T].UpdateLayout (Gallo.Mobile.UI.BaseHelpers.T data) [0x00112] in c:\Work\Gallo\EstudioGallo\Gallo.Mobile.UI\Gallo.Mobile.UI\BaseHelpers\BaseQueryPage.cs:128 ")

How do I create a layout that overlays another and let taps go through the transparent areas?

$
0
0

TL;DR: Some layouts will count a tap on a transparent background, others won't. Setting InputTransparent on a container sets it for all of its children, and I feel like children should be able to override the parent. I need to create elements that overlay another element and pass taps through a transparent region but still have tappable buttons. When I try this with a Grid, it doesn't work. I don't want to go back to AbsoluteLayouts. I'm mostly working in iOS right now, I'm not quite sure if it's a problem in Android yet. Windows Phone/UWP isn't on the table.

Longer version:

I'm rewriting some layouts that worked OK in an older Xamarin Forms (1.3 I think). We recently upgraded to 2.1, and it wreaked havoc on the layout code's bad decisions. I'm tasked with updating the layouts to behave themselves. While I recognize 2.2 has been released, I just tried an upgrade and everything I'm typing seems true in that version as well, so it's not a 2.1 vs. 2.2 issue, or at least if some improvements are made they aren't helping me.

It's a mapping application, so the centerpiece of all layouts is an expensive, temperamental OpenGL element. This element very much does not like to be reparented, so I've adopted a layout sort of like this imaginary XAML:

<ContentPage>
    <CustomLayout>
        <OurHeaderControl /> 
        <TheMapControl /> 
        <OurFooterControl /> 
        <MapOverlay /> 
    </CustomLayout>
</ContentPage

The purpose of "MapOverlay" is to implement our workflows by adding Xamarin elements on top of the header/footer areas and/or the map. For example, one layout adds a list of directions to the bottom above the footer, so it has less room for the map to appear. The custom layout understands this and lays out the map after the overlay so it can ask for the correct map bounds.

In this layout, I cannot tap on anything the MapOverlay is over. I can make it InputTransparent and tap those things, but then all of its children are also not tappable. This was not true in the old layouts.

Here's the only differences I see between the old layouts and the new:

The old layouts were a complicated mess of AbsoluteLayouts. It looked something like this, I didn't write it:

<ContentPage>
    <AbsoluteLayout> // "main layout"
        <AbsoluteLayout> // "map layout"
            <Map /> // An AbsoluteLayout containing the OpenGL view.
        </AbsoluteLayout>
        <AbsoluteLayout> // "child layout"
            <SubPage /> // An AbsoluteLayout
        </AbsoluteLayout>
    </AbsoluteLayout>
</ContentPage>

The main layout contains AbsoluteLayouts to constrain the child views. One child view is itself an AbsoluteLayout that contains the Map and a handful of other elements associated with it. The other child is the overlay, which is always an AbsoluteLayout that contains the elements relevant to that overlay. These layouts all reference each other in cycles and update each other as layout events change. It's a fascinating ping-ponging that eventually settles down. Usually. Sometimes things just disapper. Obviously there's a reason I'm rewriting it.

But I can click on what I need to click on at every layer, and I don't get that.

So, let's talk about what I need to work, and maybe figure out if it's a bug why it's not working, or if it's a coincidence that it worked with other layouts. Here's a non-XAML page layout that demonstrates, my project's got its roots in the days when you couldn't use XAML in shared libraries:

I need to be able to tap both buttons, and have them respond.

public class MyPage : ContentPage {
    public MyPage() {

        var mainLayout = new AbsoluteLayout();

        // Two buttons will be overlaid.
        var overlaidButton = new Button() {
            Text = "Overlaid",
            Command = new Command((o) => DisplayAlert("Upper!", "Overlaid button.", "Ah."))
        };
        mainLayout.Children.Add(overlaidButton, new Rectangle(0.25, 0.25, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize), AbsoluteLayoutFlags.PositionProportional);

        // The top overlay layout will be a grid.
        var overlay = new Grid() {
            RowDefinitions = { new RowDefinition() { Height = new GridLength(1.0, GridUnitType.Star) } },
            ColumnDefinitions = {
                new ColumnDefinition() { Width = new GridLength(1.0, GridUnitType.Star) },
                new ColumnDefinition() { Width = new GridLength(1.0, GridUnitType.Star) },
            },
            BackgroundColor = Color.Transparent
        };
        var overlayingButton = new Button() {
            Text = "Overlaying",
            Command = new Command((o) => DisplayAlert("Upper!", "Overlaying button.", "Ah."))
        };
        overlay.Children.Add(overlayingButton, 0, 1);
        mainLayout.Children.Add(overlay, new Rectangle(0, 0, 0.5, 0.5), AbsoluteLayoutFlags.All);

        // This pair of property sets makes the overlaid button clickable, but not the overlaying!
//      overlay.InputTransparent = true;
//      upperOverlayButton.InputTransparent = false;


        Content = mainLayout;
    }
}

I'm stumped. I really don't want to disassemble all of our layouts and put everything in one big AbsoluteLayout or a custom layout. In WPF, there were two kinds of transparent: "transparent background" meant the background could still hit test, and "null background" meant the background would not hit test. Is there some way to overlay layouts in Xamarin like this?

Or, more appropriate, why is the convoluted nest of 8 AbsoluteLayouts in our old 2.2 layouts working like I need it to, but this much simpler layout isn't?

How to use the Mono.Data.Sqlite.SqliteConnection xamarin.forms PCL

$
0
0

How to use the Mono.Data.Sqlite.SqliteConnection xamarin.forms PCL
xamarin.forms shared library can be used
How to use the Mono.Data.Sqlite.SqliteConnection xamarin.forms PCL, xamarin.forms shared library can be used in addition to the use of DependencyService.

How can two binary-equivalent packages folders give different runtime behaviour?

$
0
0

Hi,

I have an extremely bizarre situation, for which I would love someone to come up with any plausible explanation.

I have ProjectGood and ProjectBad. Both try to connect to a Microsoft Band using the Xamarin.Microsoft.Band set of packages. Both projects run the exact same chunk of code to perform the connection. One works, one fails (the call to BandClientManager.ConnectAsync() never returns).

Since the calling code is identical, I assumed there must be some problem with the packages in ProjectBad, so I did a comparison of all the package.config files and also a binary comparison of the \packages folders in each project. They were identical.

Because I didn't know what else to try, I copied the \packages folder from ProjectGood to ProjectBad, did a clean and rebuild of ProjectBad, and it worked!

I don't understand how this is possible. I guess I have to put it down to ghosts in the machine, but I can't help but be worried that I have no explanation for this behaviour. What worries me most is if I get the packages again in the future. Will my working project suddenly break and if it does how could I possibly fix it?

If anyone can offer any explanation for this strange behaviour, I would be immensely grateful.

Kind wishes ~ Patrick

problem whith interface

$
0
0

Hi,
I have one button in the form but it don´t appers on end of screen when i work with touch 5". When i has touch 3.7" or 4.0" it appears on end form. How to put this button on end form?
I atach photo for this. In end appers only black after butto. I need button on end. Thanks.

About implementing an effect with image property on Android

$
0
0

Hi, there.
I'm writing an effect in my Xamarin.Forms App, which has an property of image, and I set the property in XAML like < Button Text="ON" local:MyEffect.HighlightedImage="green.png" />
When I implement this effect on Android application, I need to set the image as background of an Android native Button, which has method of SetBackgroundImageResource() and SetBackgroundImageDrawable().
The question is, how can I convert the "green.png" string to Android native resource id or an drawable?
On iOS, this is quite simple: UIImage.FromFile("green.png"), but on Android, my file is located in Resources(xx)(x)hdpi-drawable folder and I don't know how to access it with filename string.

Can we override NAVIGATION BACK BUTTON press in Xamarin.forms?

$
0
0

Hi,

Can we override navigation back button pressed in Xamarin.forms?
I have one navigation back button and the one save button in navigation bar.Save button hits the web service and saves in asynchronous way. While saving although i used progressing bar, navigation back button can be pressed and hence the app crashes due to index out of range exception on navigation stack.I tried using OnDisappearing() , did not work. I wanna cancel the PopUpAsync(),if the save is not done completely, but failed to achieve that. Is there any solution for this scenario? Can we override the navigation back button press event using any custom renderer ?

CarouselView package?

$
0
0

Sorry if I missed it, but did they announce the CarouselView package since it was removed from 2.2?


MR.Gestures handles ALL touch gestures

$
0
0

With MR.Gestures you can handle the Tapping, Tapped, DoupleTapped, LongPressing, LongPressed, Panning, Panned, Swiped, Pinching, Pinched, Rotating and Rotated gestures on all layouts, cells, views and on the ContentPage.

The code can be as easy as

    var box1 = new MR.Gestures.BoxView { Color = Color.Red };
    box1.LongPressed += (s, e) => { Console.WriteLine("Code: Red LongPressed"); };

Or in XAML


<mr:ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:mr="clr-namespace:MR.Gestures;assembly=MR.Gestures" x:Class="GestureSample.Views.ContentViewXaml" Padding="50" TappingCommand="{Binding TappingCommand}" TappedCommand="{Binding TappedCommand}" DoubleTappedCommand="{Binding DoubleTappedCommand}" LongPressingCommand="{Binding LongPressingCommand}" LongPressedCommand="{Binding LongPressedCommand}" PanningCommand="{Binding PanningCommand}" PannedCommand="{Binding PannedCommand}" SwipedCommand="{Binding SwipedCommand}" PinchingCommand="{Binding PinchingCommand}" PinchedCommand="{Binding PinchedCommand}" RotatingCommand="{Binding RotatingCommand}" RotatedCommand="{Binding RotatedCommand}" >

MR.Gestures is available via NuGet. More info on http://www.mrgestures.com/.

There is also a sample app available to download from https://github.com/MichaelRumpler/GestureSample. The GestureSample demonstrates how to use all the gestures with all Xamarin.Forms elements.

'Circle Button' Segment Control for Xamarin form.

$
0
0

I'm newbie.
But If someone needs segment control for Xamarin form (iOS & Android), you can use mine.

Thanks.

It' first time that I uploaded my code somewhere.
Any suggestion or advice or request would be fun.

Nexttime, I will make it with image buttons.

  • CircleSegmentControl.cs

    using System;
    
    using Xamarin.Forms;
    using System.Collections;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Collections.ObjectModel;
    
    namespace XXX
    {
        [ContentProperty("ButtonList")]
        public class CircleSegmentControl : StackLayout
        {
            public event EventHandler ValueChanged;
            private readonly ObservableCollection<SegmentButton> Buttons = new ObservableCollection<SegmentButton>();
    
            Color _selectedColor = Color.Red;
            Color _unselectedColor = Color.Blue;
            Color _buttonTextColor = Color.White;
            Double _buttonWidth = 70;
            Double _fontSize = Font.Default.FontSize;
    
            public Color SegmentSelectedColor {set{ _selectedColor = value; }get{return _selectedColor;}}
            public Color SegmentUnselectedColor {set{ _unselectedColor = value; }get{return _unselectedColor;}}
            public Color SegmentButtonTextColor {set{ _buttonTextColor = value; }get{return _buttonTextColor;}}
            public Double SegmentButtonWidth {set{ _buttonWidth = value; }get{return _buttonWidth;}}
            public Double SegmentFontSize {set{ _fontSize = value; }get{return _fontSize;}}
    
            int _selectedIndex = 0;
    
    
            public CircleSegmentControl ()
            {
                Buttons.CollectionChanged += CollectionChanged;
    
                this.Orientation = StackOrientation.Horizontal;
            }
    
            public ObservableCollection<SegmentButton> ButtonList
            {
                get { return Buttons; }
            }
    
            void CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
            {
                SegmentButton button = e.NewItems [0] as SegmentButton;
                button.TextColor = _buttonTextColor;
                button.WidthRequest = _buttonWidth;
                button.HeightRequest = _buttonWidth;
                button.BorderRadius = (int)_buttonWidth / 2;
                button.FontSize = _fontSize;
                if (Buttons.Count == 1)
                    button.BackgroundColor = _selectedColor;
                else
                    button.BackgroundColor = _unselectedColor;
                button.HorizontalOptions = LayoutOptions.Center;
                button.VerticalOptions = LayoutOptions.Center;
                button.Clicked += OnSegmentButtonClicked;
    
                this.Children.Add (button);
            }
    
            public int SelectedIndex {
                set{
                    if (_selectedIndex == value)
                        return;
                    _selectedIndex = value;
                    for (int i = 0; i < Buttons.Count; i++) {
                        Button button = Buttons [i];
                        if (_selectedIndex == i)
                            button.BackgroundColor = _selectedColor;
                        else
                            button.BackgroundColor = _unselectedColor;
                    }
    
                    ValueChanged?.Invoke(this, EventArgs.Empty);
                }
                get {return _selectedIndex;}
            }
    
            void OnSegmentButtonClicked(object sender, EventArgs e)
            {
                for (int i = 0; i < Buttons.Count; i++) {
                    if (Buttons [i] == (Button)sender) {
                        SelectedIndex = i;
                        break;
                    }
                }
            }
        }
    
        public class SegmentButton : Button
        {
        }
    }
    
  • xaml

    <local:CircleSegmentControl ValueChanged="SegmentValueChanged" SegmentSelectedColor="{x:Static local:AppConstants.GlobalColor}" SegmentUnselectedColor="#EEEEEE" SegmentButtonTextColor="Black">
                                    <local:SegmentButton Text="boy"/>
                                    <local:SegmentButton Text="girl"/>
                                    <local:SegmentButton Text="boy2"/>
                                    <local:SegmentButton Text="girl2"/>
                                </local:CircleSegmentControl>
    
  • xaml.cs

    void SegmentValueChanged(object sender, EventArgs eventArgs)
            {
                CircleSegmentControl sc = sender as CircleSegmentControl;
                Debug.WriteLine (sc.SelectedIndex + " button changed!");
            }
    

Tap gesture to a globalized button ?

$
0
0

Hi,
It's easy to make a button with a tap gesture to bind it to a command : doc.
But when you need to add a label (to globalize your app) inside the image, the tap gesture is not detected because the event is on the label, which almost take all the image space.
At this moment I use a relative layout to superpose the image and the label.
I see that at this moment the label doesn't support tap gesture (?).
So any clean idea to globalize an image as a button ? (Yes I can make many images as languages I want to support, but isn't it dirty to select an image from the culture ?)

Thanks all

Best WordPress Xamarin sample

$
0
0

I'm new to app programming as well as working with VisualStudio and Xamarin.Forms. I'm looking to create an app that connect with my WordPress blogs. Does anybody know (may be GitHub link) sample of the WordPress app?

Bug on Samsung Devices...

$
0
0

Attached find sample project exhibiting the bug. Basically, in a Master/Detail app, when I have a Detail page that uses Navigate.PushAsync to display another entry type page, this entry page has issues with Switch controls on Samsung devices. Namely, some of them don't even show up.

This code DOES work on the emulator, an LG device, a BLU device...just not Samsung devices (tried a Note 8 tablet and an S5 phone).

If others can confirm that 1) it works on their non-Samsung device, and that 2) it does not work on their Samsung device, I would appreciate it. If it does work on your Samsung, please let me know what model it is. If it universally seems to not work on Samsung, I'll report it as a bug...

Essentially the app shows a Master/Detail setup. On the Detail page is a + button. Tap that, the "Entry" page should show. On that page should be three (3) switch controls. On my Samsung Note 8, for example, only the middle one shows up (the one not in an embedded StackLayout), and it shows up right justified (all the way on the right of the screen). The other two, StackLayout -ed with Labels, do not show up at all (the Labels show, just not the switches). For the quick version, the XAML looks like this for the entry page:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="SamsungSwitch.Detail1">

        <ScrollView>
            <StackLayout >

                <StackLayout Orientation="Horizontal" >
                    <Label Text="Option One" YAlign="Center"/>
                    <Switch  />
                </StackLayout>

                <Switch  />

                <StackLayout Orientation="Horizontal" >
                    <Label Text="Option Two" YAlign="Center"/>
                    <Switch  />
                </StackLayout>

            </StackLayout>
        </ScrollView>


</ContentPage>

It's in a ScrollView, because this is how our actual app is doing it, because the pages exhibiting the error in our app have more than just this handful of controls on them. So I left it that way (in the ScrollView), in case it is actually a contributing factor.

Thanks!

Viewing all 91519 articles
Browse latest View live