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

How to Put an image on a Image?

$
0
0

Hi Everyone,
Is there any way to put an uploaded image on an image

I have an image which will work as a background and then I need to put an uploaded image on it. As shown in the screenshot the area which is surrounded by rectangle, I have to put an uploaded image on it.

Thanks in advance.


Splash Screen on Android is Blank

$
0
0

Good afternoon! How are you all?

I've been trying to implement a splash screen all day following tutorials here and there. The most common solution I found was to have a XML file in the drawable folder and call a bitmap from there. It was working fine until I tried to add a different splash for landscape. It all went downhill from there.

So I found another solution: To set the content view of my SplashActivity to an XML where I set a layout and an Image. It works perfectly for portrait and landscape in preview mode. However, when I run the app, the splash screen is nowhere to be found and it only shows a blank screen.

This is my Splash Activity.

Its XML file is:

Strangely enough, when I put the SetContentView in my MainActivity it shows in there (Even though not correctly sized) so I don't think the problem is in the XML file. I really don't know what else I could try to solve this :(

Image in listview is invisible even though its IsVisible is true.

$
0
0

I have this app in XF 4.4 that I've been developing for 2 years now. Lately I noticed some weird Image control behavior. I have a ListView of ViewCells containing Image control. The image's IsVisible property is bound to a property in ProcessAction class. When the user taps a row, the image becomes visible, when it taps it once more it goes hidden. I noticed that when I make some of images visible, close the page and then open it once more (all the time with the same ViewModel) the images are hidden even though their IsVisible properties are correctly set to true. So when I tap the ViewCell once more, apparently nothing happens, as then Image's IsVisible is set to false. So it behaves like Images were not properly restored from ViewModel when page loads. It might be related to GlideX as I lately added it to my project, though I think it worked this way before.

<ListView x:Name="lstActions" ItemsSource="{Binding Items}" ItemTapped="Handle_ItemTapped" VerticalOptions="FillAndExpand" HasUnevenRows="True" SeparatorVisibility="Default" CachingStrategy="RecycleElement"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <StackLayout Padding="10"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="8*"/> <ColumnDefinition Width="2*"/> </Grid.ColumnDefinitions> <Image Source="tick_green.png" Grid.Row="0" Grid.Column="0" HeightRequest="50" IsVisible="{Binding IsChecked}" IsEnabled="{Binding IsMutable}"/> <Label Text="{Binding ActionName}" LineBreakMode="WordWrap" Style="{DynamicResource ListItemTextStyle}" FontSize="Medium" FontAttributes="Bold" IsEnabled="{Binding IsMutable}" Grid.Row="0" Grid.Column="1"/> <Image Source="exclamation_red.png" Grid.Row="0" Grid.Column="2" HeightRequest="50" IsVisible="{Binding IsRequired}"/> </Grid> </StackLayout> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView>

Code behind:

`ActionListViewModel vm;

    public ActionList(ActionListViewModel _vm)
    {
        InitializeComponent();
        vm = _vm;
        BindingContext = vm;
    }

    async void Handle_ItemTapped(object sender, ItemTappedEventArgs e)
    {
        if (e.Item == null)
            return;
        if ((bool)((IActionKeeper)e.Item).IsMutable)
        {
            if ((bool)((IActionKeeper)e.Item).IsChecked)
            {
                ((IActionKeeper)e.Item).IsChecked = false;
                IActionKeeper item = ((IActionKeeper)e.Item);
                if (vm.CheckedItems.Any(i => i.ActionId == item.ActionId))
                {
                    vm.CheckedItems.Remove(vm.CheckedItems.FirstOrDefault(i => i.ActionId == item.ActionId));
                }
            }
            else
            {
                ((IActionKeeper)e.Item).IsChecked = true;
                IActionKeeper item = ((IActionKeeper)e.Item);
                if (!vm.CheckedItems.Any(i => i.ActionId == item.ActionId))
                {
                    vm.CheckedItems.Add(ToProcessAction(item));
                }

            }
        }
        else
        {
            DependencyService.Get<IToaster>().LongAlert($"Czynność została oznaczona jako wykonana w innej obsłudze i nie można jej zmienić..");
        }



        //Deselect Item
        ((ListView)sender).SelectedItem = null;
    }`

Items property in ActionListViewModel:

private ObservableCollection<IActionKeeper> _items { get; set; } public ObservableCollection<IActionKeeper> Items { get { return _items; } set { if (_items != value) { _items = value; OnPropertyChanged(); } } }

And ProcessAction class that works as a model for listview's cell:

public class ProcessAction : Entity<ProcessAction>, IActionKeeper, INotifyPropertyChanged
    {
        public int ProcessActionId { get; set; }
        public override int Id
        {
            set => value = ProcessActionId;
            get => ProcessActionId;
        }

        public Nullable<int> ProcessId { get; set; }
        public Nullable<DateTime> PlannedStart { get; set; }
        public Nullable<DateTime> PlannedFinish { get; set; }
        public string PlaceName { get; set; }
        public Nullable<int> ActionId { get; set; }
        public string ActionName { get; set; }
        public int? GivenTime { get; set; }
        public int? HandlingId { get; set; }
        public string Type { get; set; }
        public int? PlaceId { get; set; }
        public bool? _IsMutable { get; set; } = true;

        public bool? IsMutable
        {
            get
            {
                return _IsMutable;
            }
            set
            {
                if (value != _IsMutable)
                {
                    _IsMutable = value;
                    OnPropertyChanged();
                }
            }
        }

        public bool IsRequired
        {
            get
            {
                if (PlannedStart == null)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
        }

        public bool? _IsChecked { get; set; }
        public bool? IsChecked
        {
            get
            {
                if (_IsChecked == null)
                {
                    return false;
                }
                return _IsChecked;
            }
            set
            {
                if (value != _IsChecked)
                {
                    _IsChecked = value;
                    OnPropertyChanged();
                }
            }
        }

        public List<DateTime?> LastChecks { get; set; }
        public DateTime? LastCheck
        {
            get
            {
                if (LastChecks.Any())
                {
                    return LastChecks.FirstOrDefault();
                }
                else
                {
                    return null;
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged([CallerMemberName] string name = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
        }
    }

Thumb switch has disappeared in Android after update Xamarin.Forms from 2.5 to 4.5

$
0
0

After updating Xamarin.Forms the Switch's look like this:
off: on:

This is the code:

_check = new Switch
{
    VerticalOptions = LayoutOptions.Center
}

In the style.xml file I have the key: @color/AccentColor
And in colors.xml I have: #FFDA125F

If I add ThumbColor property:

_check = new Switch
{
    VerticalOptions = LayoutOptions.Center,
    ThumbColor = Color.FromHex("#f1f1f1")
}

The Switch's look like this:
off: on:

But I want this looks like:

I don't know why that happened after the update. Does anyone have any idea what could be happening?

How to approach an auto-synchronization when internet is back online?

$
0
0

I am working on a Xamarin Forms application that allows you to submit Orders.

An order is composed with one ore multiple items, and an item can have many pictures.

To submit an Order to the server, these are the steps:

  • Make a request to create an Order. -> it returns the Order Id.
  • Make a request passing the list of items and the Order Id to create the Items. -> returns item ids.
  • Make a request for each picture using the corresponding item id.

The submission of the Order is working fine, but I have a use case were if there is no internet connection, the Orders enters in a "Pending to Submit" status, and when the device gets online again, it will automatically submit all the Orders with "Pending to Submit" status.

To do this, I have subscribed to the ConnectivityChanged event of the Xamarin Essentials Connectivity plugin, and when I detect that user has internet access, I start submitting each Order at a time. I don't know if there is a better solution to do this.

Also, there is a posibility that in the middle of a submission internet goes offline again, so maybe an Order was created, but the list of items are stuck in the middle without internet and the whole operation gets corrupted.

Any thoughts?

Xamarin Forms Android App Connect/Communicate via USB to PC

$
0
0

Hello,
I am working on an Android (Xamarin Forms) application, and have a need to communicate with a Windows PC. This communication NEEDS to happen over USB cable. I googled this problem and found a couple of incredibly similar projects anotherlab's UsbSerialForAndroid, and lusovu's XmarinUsbSerial.

I am using anotherlab's project as a starting point on how to get android -> pc usb comms working, but am running into the problem of never being able to find any devices when the tablet is plugged into the PC. I have tried using a regular USB cable as well as an OTG cable without any luck. I just can't figure out why the device list is empty when using the following lines of code:

    usbManager = GetSystemService(Context.UsbService) as UsbManager;
    IDictionary<string, UsbDevice> devices = usbManager.DeviceList;

I'm thinking it might be a problem with the drivers it's using but I have no clue as to how to get the vendor id or the product id of the usb host controller in my laptop (done a quick search). Could it be something else?

I can connect to an Arduino device using the OTG cable and can get the project working with it, but I need it to work with a PC not an Arduino.

If anyone has any ideas I would be grateful,
Thanks

Is there a good plugin for this for Xamarin.forms?

$
0
0

Unfortunately, I don't know what this type of control is called so I'm simply going to leave a picture of it here. I'm essentially wanting to open a page kind of like modal style from the bottom of the page and have it stay just shy of the top. Almost exactly like the picture below. Anyone know of a good nugget plugin for this?

Also what is this type of (window?) called?

TabbedPage - tabs on top iOS

$
0
0

Hi,

Is it possible without any 3rd party library to simply put the tabs of a TabbedPage on the top of the screen in iOS? (Like this library is doing: https://github.com/NAXAM/toptabbedpage-xamarin-forms)

Second question on the same topic is how can I change the color of the Tabs for iOS?

Best regards


xamarin forms: System.ArgumentNullException has been thrown (IOS)

$
0
0

I am using webview for parsing my HTML data. For this, I am using a custom render.

In the Main Project:

public  class MyWebView : WebView
{
    public static readonly BindableProperty UrlProperty = BindableProperty.Create(
    propertyName: "Url",
    returnType: typeof(string),
    declaringType: typeof(MyWebView),
    defaultValue: default(string));

    public string Url
    {
        get { return (string)GetValue(UrlProperty); }
        set { SetValue(UrlProperty, value); }
    }
}

Ios Renderer

public class MyWebViewRenderer : ViewRenderer<MyWebView, WKWebView>
{
    WKWebView _wkWebView;
    protected override void OnElementChanged(ElementChangedEventArgs<MyWebView> e)
    {
        base.OnElementChanged(e);

        if (Control == null)
        {
            var config = new WKWebViewConfiguration();
            _wkWebView = new WKWebView(Frame, config);
            SetNativeControl(_wkWebView);
        }
        if (e.NewElement != null)
        {
            Control.LoadHtmlString(Element.Url, null);   //use this code instead
            //Control.LoadRequest(new NSUrlRequest(new NSUrl(Element.Url)));
        }
    }
}

In XAML and XAML.cs:

<local:MyWebView 
    x:Name="web_view"
    VerticalOptions="FillAndExpand"/>

web_view.Url = htmldata;

But I am getting System.ArgumentNullException when running the project.

Screenshots:

enter image description here

I have uploaded a sample project here.

How to implement NFC in Xamarin.Forms

$
0
0

Hello,

I need to implement a Xamarin.Forms application that can read NFC tags. Regarding this, I have 2 questions:

  1. How to enable NFC in Android Emulator

I have used _nfcAdapter = NfcAdapter.GetDefaultAdapter(this); in MainActivity OnCreate method, but null is returned

  1. How to emulate the tag presence

When I could enable NFC in Android Emulator, how can I emulate the tag presence?

Regards
Jaime

ImageButton binding with ListView

$
0
0

Hi,
I'm trying to make an app with a listview that, by clicking the image it pushes to a new navigation page with that item details.
How can i bind the ImageButton with the listview item?

Any suggestions?
<ImageButton Source="{Binding srcImmagine}" Aspect="AspectFit" Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" HeightRequest="100" WidthRequest="100" HorizontalOptions="Start" Clicked="ImageButton_Clicked" BackgroundColor="Transparent"/>

Xamarin Forms Shell separator between flyout items

Could I sort a ListView or a ListView.ItemTemplate by a value in a specific?

$
0
0

Hi, I trying to sort or order a ListView by a value in a specific, for example by date but I haven't anything like that,
My ListView:

<ListView  x:Name="ItemsListView" RefreshCommand="{Binding LoadItemsCommand}" IsRefreshing="{Binding IsBusy, Mode=OneWay}" SeparatorVisibility="None" Style="{ StaticResource ResponsiveLandscapeMarginStyle }" ItemsSource="{ Binding Messages }">
        <ListView.RowHeight>
            <OnIdiom x:TypeArguments="x:Int32" Phone="120" Tablet="160" />
        </ListView.RowHeight>

    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>

                <local:DataItemTemplate />

            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Is there a way to sort by date or by any value, to display the values in the ListView?

Selecting a particular element of collectionview in UI test

$
0
0

I am performing UI test for a collection view of items. The number of items in the collection view is dynamic.
The xaml code defining the collectionview is as follows.

By this code(shown as below)
app.Tap(x => x.Marked("VehicleListAutoId").Child());
I was able to select the first element in the collection view. How can I select other element from the collection view?
i.e. I don't want the first element to be clicked, rather I want second, or third element to be clicked.

Anyone successfully passed cookies to WkWebView?

$
0
0

I have been working on a Custom WebView that on iOS uses the native WkWebView instead of the default.
My pain is that passing cookies to it from a HttpClient does not always sent those cookies on first request.
The intention is that the user, already being logged in using a HttpClient, opens a page showing the webpage of our service. By reusing the cookies, the user does not need to authenticate again. But by using the WkWebView, I sometimes end up on the loginpage, as a result of cookies not being passed properly.

This is my iOS Custom Renderer for the WebView:

public class CustomWebViewRenderer : ViewRenderer<CustomWebView, WKWebView>
{
    protected override async void OnElementChanged(ElementChangedEventArgs<CustomWebView> e)
    {
        base.OnElementChanged(e);

        if (e.NewElement != null)
        {
            if (Control == null)
            {
                var config = new WKWebViewConfiguration();

                var jCookies = Appl.FlurlClient.Cookies.Values;

                NSHttpCookie[] nsHttpCookies = jCookies.Where(c => c != null).Select(c => new NSHttpCookie(c)).ToArray();

                foreach (var c in nsHttpCookies)
                {
                    await config.WebsiteDataStore.HttpCookieStore.SetCookieAsync(c);
                }

                var webView = new WKWebView(Frame, config);
                SetNativeControl(webView);
            }
            Control.LoadRequest(new NSUrlRequest(new NSUrl(Element.Uri)));
        }
    }
}

Lifecycle events with modal popups

$
0
0

Hi.

What is the recommended pattern for setting things up in a page in an asynchronous manner, that does not get retriggered when a modal dialog has been dismissed on top of the page?

I currently do:
public partial class MyPage : ContentPage
{
...
private bool hasAppeared;
...

    protected override async void OnAppearing()
    {
        base.OnAppearing();

        if (this.hasAppeared) // for modal popups
            return;
        this.hasAppeared = true;

      // my code here...
    }
}

but surely there's a better way? I was looking for overloads of OnAppearing with some state information being sent in there but none seem to exist.

Thanks!

mscorlib conflict between versions

$
0
0

Hello

I have a Xamarin Forms Shared Project which can build and deploy without errors. However, the following build warning have appeared:

There was a conflict between "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" and "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e".
1> No way to resolve conflict between "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" and "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e". Choosing "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" arbitrarily.

The build warning seems to have appeared after updating Visual Studio and I cannot get rid of it.
I have tried cleaning the project, removing bin folder, .vs folder and building a new project with the same dependencies but that does not replicate the warning.

I have found other posts with a similar issue to this but I do not know if those problems are related:
https://developercommunity.visualstudio.com/content/problem/45257/no-way-to-resolve-conflict-between-mscorlib-versio.html
https://forums.xamarin.com/discussion/71781/how-to-get-rid-of-there-was-a-conflict-between-warnings-reported-between-different-packages
https://forums.xamarin.com/discussion/100868/mscorlib-version-2-0-5-0-vs-version-4-0-0-0#latest

I have the following versions:

Microsoft Visual Studio Enterprise 2017
Version 15.3.2
VisualStudio.15.Release/15.3.2+26730.10
Microsoft .NET Framework
Version 4.6.01586

Installed Version: Enterprise

Architecture Diagrams and Analysis Tools 00369-60000-00001-AA938
Microsoft Architecture Diagrams and Analysis Tools

Visual Basic 2017 00369-60000-00001-AA938
Microsoft Visual Basic 2017

Visual C# 2017 00369-60000-00001-AA938
Microsoft Visual C# 2017

Visual F# 4.1 00369-60000-00001-AA938
Microsoft Visual F# 4.1

Application Insights Tools for Visual Studio Package 8.8.00712.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017 15.0.30726.0
ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services 1.0
Provides languages services for ASP.NET Core Razor.

ASP.NET Template Engine 2017 15.0.30726.0
ASP.NET Template Engine 2017

ASP.NET Web Frameworks and Tools 2017 5.2.50601.0
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0 15.0.30728.0
Azure App Service Tools v3.0.0

Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

JavaScript Language Service 2.0
JavaScript Language Service

JetBrains ReSharper Ultimate 2017.1.3 Build 108.0.20170613.154143
JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright © 2017 JetBrains, Inc.

Merq 1.1.17-rc (cba4571)
Command Bus, Event Stream and Async Manager for Visual Studio extensions.

Microsoft Azure Tools 2.9
Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.50719.1

Microsoft Continuous Delivery Tools for Visual Studio 0.3
Simplifying the configuration of continuous build integration and continuous build delivery from within the Visual Studio IDE.

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger 1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Mono Debugging for Visual Studio 4.6.8-pre (ec7034f)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 4.3.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

SQL Server Data Tools 15.1.61707.200
Microsoft SQL Server Data Tools

TypeScript 2.3.4.0
TypeScript tools for Visual Studio

Visual Studio Code Debug Adapter Host Package 1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Xamarin 4.6.0.299 (b63523e27)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android SDK 7.4.0.21 (2851083)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK 10.12.0.20 (80b8487)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

I would like to know the cause of this, and if it is a serious problem that should be fixed?

I have attached the full warning

Thanks in advance :)

Override Single Setter of StaticResource Style possible?

$
0
0

Hi,

in App.xaml I have defined a Style like this:
<Style TargetType="Label" x:Key="ControlLabel"> <Setter Property="FontAttributes" Value="Bold" /> <Setter Property="TextColor" Value="Blue" /> <Setter Property="Margin" Value="0,10,0,0" /> </Style>

Now I use this everywhere, but on one Special Label I want to remove the Margin, so I tried this:
<Label Text="Text" Style="{StaticResource ControlLabel}" Padding="0,0,30,0" Margin="0,0,0,0"/>

But the Margin is still 10. How can I override a specific Setter inline?

Thank you

How to set an imageview to center in iOS Launchstoryboard?

What is involved in creating or more deeply customizing GTK controls?

$
0
0

I'm working on a project that's Android/GTK cross-platform, and one of the main goals is a mobile look-and-feel for the GTK app (Its on a Pi with a touchscreen). I've gotten started working with custom renderers and while this allows me to get closer to mobile style controls in some cases, Many of the controls offer very little customization with custom renderers, at least as far as I can tell.

For example, with a SearchBar control, I can make some minor changes to the GTK renderer, but some of the most visually important parts of the control, like the search icon, are set in a private field with no methods to access them, in the Forms.Platform.GTK SearchEntry class that, to my knowledge, I am unable to do any work on within my project. (Please, if I am grossly misunderstanding how to work with these files, let me know).

Basically, my questions is, where do I start with this? Am I over complicating what's involved in more significantly changing the look and feel of these controls while keeping basically all the same functionality? If I need to create new controls, do I have to do them in MonoDevelop working with GTK widgets? Or is this something I can do in the same environment and language as my project with the Platforms.GTK library? Is there a completely different option I'm not aware of?

There are almost no resources other than repositories that discuss work with Xamarin.Forms.GTK in general, nevermind in depth custom renderer work, so any insight, guidance, resource or instruction is beyond appreciated. Thanks very much.

Viewing all 91519 articles
Browse latest View live


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