I want to create a Xamarin Forms Editor Control that changes its height when it gets filled(Adds a new line when space in previous line finished). I'm only interested in WinPhone and Android Platfroms.
The Editor itself doesn't support such property.
I know that the Android native control (EditText) supports it (Not sure about the WinPhone variant, TextBox). But I'm not sure how to implement it.
It will be very helpful if someone can explain me how to create the renderers for these platforms.
Edit
I found this partial solution, it kind of works fine but it is not so natural(as for example EditText in Android).
class RoundedEditor : Editor
{
public RoundedEditor()
{
this.TextChanged += (sender, e) => { this.InvalidateMeasure(); };
}
}
I'll be glad if someone will provide a better solution.
Edit 2
Here are the results of how it works now:
UWP
Writing first line:
pressing enter:
The previous line is not showed completely as I would like.
Android
In android it actually works great:
You will have to implement a custom Android EditText, and then use it for your XamarinForms control (by implementing a custom renderer for it)
Take a look at this implementation of resizable EditText:
https://github.com/ViksaaSkool/AutoFitEditText
You'd have to translate it to C# obviously, but its a great start point.
Related
i just downloaded the naxam mapbox and am completely lost the github page isn't much of help and there seems to be nothing else can anyone give anything usefull on how to implement the map view in the xamarin.forms app and thanks.
Short Anwser:
The Naxam.Mapbox for Xamarin.Forms Nuget Package, and all the associated Forms ones, have not been update since Sep 12, 2018, and the Mapbox SDK's for Android/iOS have changed since then, i tried this package and it's a bit clunky, i have manage to display the map, but inserting Geojson Sources/ Markers is not a pleasant experience.
EDIT 2019/10/13
Last month, Naxam updated their nuggets to the latest Mapbox version for .Forms, Android and iOS
Long Anwser:
If you really want to use Mapbox in your Xamarin Projects, the Naxam Binding Libraries for Android and iOS are still working today (18/06/2019), So one way to have it working for a Xamarin Forms Project is to implement both sdk's in their respective project, and use them in a Custom View Renderer (and be carefull, because those projects still need other Nuget Packages to work, and they don't warn you when you install them, be sure see the dependecies in the links i gave above).
Other way to have a map in your project is by using MapsUi (Remember that MapsUi is TileBased and Mapbox is VectorBased, so you might see less fluidity while using MapsUi). i will leave here some relevant code for the custom render in iOS for the implementation of MapsUi to get started:
MapViewRenderer.cs
public class MapViewRenderer : ViewRenderer<MapsUIView, Mapsui.UI.iOS.MapControl>
{
Mapsui.UI.iOS.MapControl mapNativeControl;
MapsUIView mapViewControl;
protected override void OnElementChanged(ElementChangedEventArgs<MapsUIView> e)
{
base.OnElementChanged(e);
if (mapViewControl == null && e.NewElement != null)
mapViewControl = e.NewElement;
if (mapNativeControl == null && mapViewControl != null)
{
var rectangle = mapViewControl.Bounds;
var rect = new CGRect(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
mapNativeControl = new Mapsui.UI.iOS.MapControl(rect)
{
Map = mapViewControl.NativeMap,
Frame = rect
};
SetNativeControl(mapNativeControl);
}
}
}
This is the base on how to implement the MapView in a Custom View Render in iOS, similiar code is needed for Android, and of course, the Custom Renderer itself, wich there is tons of tutorials on how to do it, like this ones: Source 1 Source 2
I am currently developing a Xamarin.Forms application. I am using IconizePlugin. The app is tabbedPage based and on toolbar I'm trying to include icons for some actions.
This is whay I'm getting:
Icons are showing well and in Xamarin.iOS gets the click event, while it is not working in Xamarin.Droid.
I included the corresponding nugets and followed every steps told in documentation and can't archive this. Other iconize controls in Droid are working fine except the IconToolbarItem.
Please help!
The workaround I found was to declare de IconToolbarItem in the c# code instead of xaml. Although I don't know why it wasn't working while on xaml.
Declaring the item li
ToolbarItems.Add(new IconToolbarItem
{
Icon = "fa-plus",
IconColor = Color.White,
Command = new Command(this.addBono)
});
Hello Everyone I want to share the Text on Xamarin Form using Library plugin.share. I have successfully implemented the library and on android i can able to share the text but in iOS it returns me nothing. i have done the share code on button click event so when i click on button in iOS its doesn't returns me anything.i tried the Below code but doesn't got succeed
CrossShare.Current.Share("Hii alll", "Share");
please help me to get out of this,thanks in advance
You want to take a look at UIActivityViewController, you can find the documentation here https://developer.xamarin.com/api/type/MonoTouch.UIKit.UIActivityViewController/
And Xamarin.Forms specific example http://devcenter.wintellect.com/jwood/implementing-sharing-in-xamarin-forms
This is a bit old, but I was having a similar issue and was able to resolve it.
First of all, you need to add the plugin Plugin.Share to ALL Xamarin.Forms projects (Portable, iOS, Android, UWP).
In the class that references the share code, add...
using Plugin.Share;
using Plugin.Share.Abstractions;
CrossShare.Share() doesn't work with strings, directly. You need to new up a ShareMessage.
var title = "Title For The Share";
var message = "Text to share.";
await CrossShare.Current.Share(new ShareMessage { Text = message, Title = title });
I can't say specifically to iOS, as I don't have a Mac and can't test that project, but Android and Windows 10 is working.
Hi Xamarin/MvvmCross devs,
This is just a question out of curiosity. In one of the apps I'm developing some behaviour changed. Specifically on iOS when binding the UISwitch "On" value to a boolean in the ViewModel. The getter on the property fires when the binding is applied as well as the setter when the switch is flipped, but the UI does not reflect it. Forcing me to go from just
var set = this.CreateBindingSet<SettingsView, SettingsViewModel>();
set.Bind(PushNotificationSwitch).For(s => s.On)
.To(vm => vm.ReceivePushNotifications);
set.Apply();
To having to also add the following below that (to get the UI of the switch to reflect the value)
var settingsViewModel = ((SettingsViewModel)ViewModel);
PushNotificationSwitch.On = settingsViewModel.ReceivePushNotifications;
I left the binding, as well as the new code to reflect UI state, because in addition to the UI just reflecting the correct state, I also want it to change the state in my settingsService when the user changes it.
I recently upgraded through Xamarin Studio on Mac and my iOS Xam version is Version: 10.0.0.6. Unfortunately I didn't check what version I upgraded from, but I always upgrade as soon as I see there's one available, so it should be the previous stable version.
My questions are:
Has any of you experienced similar issues where bindings changed in this way?
Since the Android binding still works fine, do you think it's an issue in MvvmCross, or iOS Xamarin Changes
Any speculations as to what could be causing this? And other parts that you think this might affect, so I won't have to go scour for bugs if none exists. Commands, text and custom control bindings are working fine (as far as I've tested)
If this question would be better suited somewhere else please let me know, I'm just curious about this behaviour.
Thanks
As we worked out in the comments of the OP the event of the switch was linked out. Hence, the binding did nothing.
Easiest way to remedy this is to add the following code to your LinkerPleaseInclude.cs file, which MvvmCross provides in the Startup NuGet and through the templates available for Visual Studio and Xamarin Studio:
public void Include(UISwitch sw)
{
sw.On = !sw.On;
sw.ValueChanged += (sender, args) =>
{
sw.On = false;
};
}
This will tell the Linker that there is a direct usage of both the ValueChanged event and the On property, since the LinkerPleaseInclude class uses the Preserve attribute.
My issue was born in Does MvvmCross work in Xamarin Studio?. MvvmCross works fine in Visual Studio. However, I've been mandated to deploy this corporately using Xamarin Studio which is what their build server uses. I ran into the issue with System.Windows.Input.ICommand not being found by the compiler during my Xamarin Studio build. ICommands appear to be used quite extensively throughout MvvmCross for user commands (MvxCommand, which implements System.Windows.Input.ICommand). I've tried creating my own version of ICommand via the following code:
using System;
namespace Something.Common
{
public interface ICommand
{
event EventHandler CanExecuteChanged;
bool CanExecute(object parameter);
void Execute(object parameter);
}
}
All good, but still doesn't fix MvxCommand, because it implements the interface System.Windows.Input.ICommand. So I created my own version, MvxCommandEx, which is basically copied from Stuart's MvxCommand and implements my own ICommand (Something.Common.ICommand).
Lo and behold, it builds. It deploys. It got me all excited. But.... it didn't work. Any place I've bound a UI element to my custom ICommand just doesn't do anything. It's as if the binding from the Click event of the control to the view model's command is just not there anymore, whether I bind it in the .axml layout file... or use the CreateBindingSet method built-in to the view.
Now... I can get around this for some things... for instance, if I use a standard android Button, and invoke the view model's command manually from the built-in Click event, like:
btnAddScope.Click += (o, i) => { _ViewModel.RequestAddScope.Execute(null); };
it works, and I'm okay doing it this way in the interim until Xamarin releases their PCL support. But I'm using an MvxListView in another section of the app that was bound the old way using a syntax like:
lst.ItemClick = _ViewModel.RequestViewScope;
where lst is a MvxListView.
This won't work, however, because lst.ItemClick expects a System.Windows.Input.ICommand, and my ICommand isn't in that namespace.
Stuart provided explanations for this that supposedly are supposed to work. However, I'm feeling stupid for not being able to implement the ICommand in a way that actually works, when it feels like it should work... so before I go down a different avenue to address this, I wanted to see if anyone could shed light on what I'm doing wrong.
The easy solutions are:
either to provide your own implementation for the Xamarin version of System.Windows.Input.ICommand and to use this implementation
or to use the mvvmcross binaries which are built on the mac.
I'd recommend the first.
If you delete your Something.Common.ICommand code abd then put your MyCommand class implementation in the same project/assembly as your viewmodels, then they should build and run fine on both windows and on mac.