I'm working on a project in which I can use MapFragment or SupportMapFragment as a custom control.
I tried to mix custom control(N-18) and Fraggle(N-26) tutorial but I can't make it work.
My Custom Control Class:
public class CustomMapView : MvxFragment
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var ignored = base.OnCreateView(inflater, container, savedInstanceState);
return this.BindingInflate(Resource.Layout.CustomMapViewLayout, null);
}
}
My CustomMapViewLayout.axml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
In the FirstView.axml I reference the CustomMapView:
<cc.CustomMapView
android:layout_width="match_parent"
android:layout_height="match_parent" />
(I use the ViewNamespaceAbbreviations in the Setup.cs)
When I try to deploy I get these errors:
MvxBind:Error View Type Not Found - cc.CustomMapView (I'm sure the namespace is correct)
Android.Views.InflateException:Loading...
Is there anybody who managed to solve this kind problem?
As far as I know, fragments have to be used within FragmentActivity parents and have to be loaded either using the fragment xml tag or using one of the (support) fragment manager methods for dynamic loading within a parent viewgroup.
The Mvx code which is reporting View Type Not Found - cc.CustomMapView definitely won't work - it's looking for a class which inherits Android View in that namespace, not looking for a Fragment.
There may be ways to write more 'dynamic' fragment xml code - but none of the mvvmcross contributors have unearthed any of these yet. For now, I think you'll have to use the Fragments more 'conventionally' - like the ways shown in the N=26 sample
Related
I am working on an application that is Xamarin Native using MvvmCross. I have spent the afternoon looking for an example of how to bind a list of strings to a table view in iOS but every example is binding to a List of Models and not string. I know this can be done in android...
<Mvx.MvxListView android:id="#+id/lvErrors"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/lblCaption"
android:layout_alignParentLeft="true"
local:MvxBind="ItemsSource Errors" />
where "Errors" is a List of strings. However trying a similar approach in iOS fails to load data.
var set = this.CreateBindingSet<ViolationDetailsView, ViolationDetailsViewModel>();
var source = new MvxStandardTableViewSource(ErrorsTableView, "TitleText Errors;");
ErrorsTableView.Source = source;
set.Bind(source).To(vm => vm.Errors);
set.Apply();
Can anyone point me in the right direction to find an example of this?
I ended up finding the answer here. "If you want to bind to the whole string object then use a . period for whole object binding."
So...
var source = new MvxStandardTableViewSource(ErrorsTableView, "TitleText Errors;");
became...
var source = new MvxStandardTableViewSource(ErrorsTableView, "TitleText .;");
I knew it was something simple.
Can you help me implement a SliderRange in Xamarin Android, I have searched, but there is only information for xamarin forms, or do they have a link with documentation on how it is used?
I recently had a similar implementation on Android and iOS and RangeSlider was the component I used for making a Slider Range :
RangeSlider is a slider control with two handles, allowing users to specify two values in a range. RangeSlider supports iOS and Android and is styled to look like a native slider control on each platform.
You might have to say that components are obsolete and will be removed soon rest assured they will be moving things to NuGet then.
And you can find the same here (For Assurance)
Through Xml you can use it like this:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<rangeslider.RangeSliderView
android:id="#+id/rangeSlider"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
min_value="0"
max_value="100"
left_value="20"
right_value="80"/>
</LinearLayout>
Programmatically you can do something like this:
using RangeSlider;
...
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
var slider = new RangeSliderView (this);
AddContentView (slider, new ViewGroup.LayoutParams (
ViewGroup.LayoutParams.FillParent,
ViewGroup.LayoutParams.FillParent));
}
Goodluck!
Incase you have issues surely revert!
using Xamarin.RangeSlider;
private LinearLayout LinearRoot;
protected override void InitViews()
{
LinearRoot = mView.FindViewById<LinearLayout>(Resource.Id.layoutRangeRoot);
var slider = new RangeSliderControl(this.Activity);
LinearLayout LinearRange = new LinearLayout(this.Activity);
LinearRange.Orientation = Orientation.Horizontal;
LinearRange.AddView(slider);
LinearRoot.AddView(LinearRange);
}
Issue:- local:MvxLang failed to bind the resource text to TextView when it is part of itemtemplate of MvxListView in Xamarin app using localization feature in MVVMCross.
My application is Xamarin.android, using MVVMCross, used Localization feature of MVVMCross with resx file.
Running sample can be found here:https://github.com/pallaviak1/RestaurantBilling.Droid
I am getting localized string through code using below syntax in viewmodel (AllBillsViewModel) BillClickedCommand:-
_dialogService.ShowAlertAsync( string.Format(TextSource.GetText("InformationReceivedMessage"), bill.CustomerEmail, bill.AmountPaid), TextSource.GetText("InformationReceivedHeader"), TextSource.GetText("InformationReceivedButtonText"));
Also my main view page where local:mvxLang is button attribute, which shows button text from resource of selected culture, also works well.
<Button ... local:MvxLang="Text ViewBillsResourceText" local:MvxBind="Click NavigateAllBills" />
Problem:- However when I am using MvxLang in controls which are part of item template of MvxListView control the localized string is blank (not populated).
file:- RestaurantBilling.Droid\RestaurantBilling.Droid\Resources\layout\ListItem_Bill.axml
The control which is part of item template view looks like below:-
<TextView android:layout_alignParentBottom="true"
android:layout_marginLeft="50dp"
android:layout_marginRight="16dp"
android:layout_width="90dp"
android:layout_height="wrap_content"
local:MvxLang="Text CustomerEmailTextView" />
The mail list control looks like below:-
<Mvx.MvxListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="ItemsSource AllBills; ItemClick BillClickedCommand"
local:MvxItemTemplate="#layout/listitem_bill" />
CustomerEmailTextView resource key is present in resx files as Name: AllBillsViewModel.CustomerEmailTextView, value : "US Customer Email".
Just to add, my Localization code is as below:-
Resource files are present in library MVVMCross.Localization, whose reference is added in RestaurantBilling.core library as well as android project.
code in core, App.cs file as below:-
Mvx.RegisterSingleton<IMvxTextProvider>
(new ResxTextProvider(Strings.ResourceManager, currentCulture));
BaseViewModel has below code:-
public IMvxLanguageBinder TextSource =>
new MvxLanguageBinder("", GetType().Name);
Getting warning in visual studio output window as below:
[0:] MvxBind:Warning: 9.78 Unable to bind: source property source not found Property:TextSource on Bill
02-10 07:41:52.020 I/MvxBind ( 4357): 9.78 Unable to bind: source property source not found Property:TextSource on Bill
I could not find enough help on MVVMCross formal website, also could not find much discussion points on same. The same thing is working in sample downloaded "My Trains" when referred from pluralsight training.
Please help.
my problem is resolved. ref link: How to bind ItemClick in MvxListView in MvxListView
This link issue is somewhat similar. I resolved the issue in below way,
whatever TextSource property I have added in viewModel, I need to put in Bill.cs class which is model
public IMvxLanguageBinder TextSource
{
get {
//Mvx.Trace("****************TextSource get in bill.cs**************************");
return new MvxLanguageBinder("", GetType().Name);
}
}
Then, the resource text key looks like below:-
Bill.CustomerEmailTextView
This is kind of workaround, actually BaseViewModel has TextSource property however it is not useful in case of item template case.
Please let me know if you have better solution because we are kind of mixing viewmodel and model properties.
I'm using MvvmCross 3.0.14 with Xamarin.Android.
I have an MvxImageView that I can get to display a particular local graphics resource if I specify the image directly (without binding) using android:src:
<Mvx.MvxImageView
android:layout_width="100dp"
android:layout_height="75dip"
android:layout_weight="1"
android:src="#drawable/Card_kh"/>
But I can't get the same image to show up using local:MvxBind:
<Mvx.MvxImageView
android:layout_width="100dp"
android:layout_height="75dip"
android:layout_weight="1"
local:MvxBind="ImageUrl 'res:Card_kh'"/>
This does not work. MvxAndroidLocalFileImageLoader.LoadResourceBitmap logs a trace message indicating that 'Card_kh' was not a known drawable name. It's encouraging that it got that far -- at least I know that the intended consumer of this information did get it. But apparently I have not provided that information in the correct format.
Taking it one step further, my actual goal is to have my ViewModel determine what resource should be used, e.g.
class MyViewModel : MvxViewModel
{
public string SomeImagePath { get { return "res:Card_kh"; } }
}
and
<Mvx.MvxImageView
android:layout_width="100dp"
android:layout_height="75dip"
android:layout_weight="1"
local:MvxBind="ImageUrl SomeImagePath"/>
What do I need to do to have an MvxImageView bind to a view-model determined local resource image?
The problem was only capitalization in the resource name. Although the image filename starts with a capital C, and the android:src attribute works with a capital C, the MvxBind of ImageUrl requires a lowercase c:
<Mvx.MvxImageView
android:layout_width="100dp"
android:layout_height="75dip"
android:layout_weight="1"
local:MvxBind="ImageUrl 'res:card_kh'"/>
This also solves the problem when the source of the ImageUrl value is a viewmodel property:
class MyViewModel : MvxViewModel
{
public string SomeImagePath { get { return "res:card_kh"; } }
}
and
<Mvx.MvxImageView
android:layout_width="100dp"
android:layout_height="75dip"
android:layout_weight="1"
local:MvxBind="ImageUrl SomeImagePath"/>
The previous answer is not working anymore since MVVMCross v6.0.0.
As described here https://www.mvvmcross.com/documentation/upgrading/upgrade-to-mvvmcross-60 MvxImageView has been removed from the API.
The newest alternative is now https://github.com/luberda-molinet/FFImageLoading/wiki/MvvmCross.
This nuget package "Xamarin.FFImageLoading" must be added in order to make the code below work.
<ffimageloading.cross.MvxCachedImageView
android:layout_width="100dp"
android:layout_height="75dip"
android:layout_weight="1"
local:MvxBind="ImagePath SomeImagePath"/>
I want to use MVVMCross, however for my android application I also want to use other libraries (sliding menu and action bar) which require me to inherit my activity classes from their custom class. This prevents me from inheriting MvxActivity, but I noticed that in MVVMCross for iOS, you can do all your bindings in code (see https://github.com/slodge/NPlus1DaysOfMvvmCross/blob/master/N-00-FirstDemo/FirstDemo.Touch/Views/FirstView.cs)
var set = this.CreateBindingSet<FirstView, FirstViewModel>();
set.Bind(textEditFirst).To(vm => vm.FirstName);
set.Bind(textEditSecond).To(vm => vm.LastName);
set.Bind(labelFull).To(vm => vm.FullName);
set.Apply();
Is there any way to do that in Android?
Yes - you can use fluent bindings in Android if you want to.
Exactly the same code should work.
You'll need to get references to the ui controls using FindViewById<Type>(), then you can bind them.
For example, in TipCalc you can add identified controls like:
<EditText
android:id="#+id/FluentEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:textSize="24dp"
android:gravity="right"
/>
and then implement binding using:
protected override void OnViewModelSet()
{
SetContentView(Resource.Layout.View_Tip);
var edit = this.FindViewById<EditText>(Resource.Id.FluentEdit);
var set = this.CreateBindingSet<TipView, TipViewModel>();
set.Bind(edit).To(vm => vm.SubTotal);
set.Apply();
// for non-default properties use 'For':
// set.Bind(edit).For(ed => ed.Text).To(vm => vm.SubTotal);
// you can also use:
// .WithConversion("converter", "optional parameter")
// .OneTime(), .OneWay() or .TwoWay()
}
Additionally, you can convert any FooActivity into a data-binding MvxFooActivity by:
inheriting from FooActivity to provide events from lifetime events in an EventSourceFooActivity
inheriting from EventSourceFooActivity to provide a datacontext in an MvxFooActivity
you can then write your code inside activities inheriting from MvxFooActivity
To see, the code required, see:
https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Droid.Fragging/MvxEventSourceFragmentActivity.cs
https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Droid.Fragging/MvxFragmentActivity.cs
You'll see the same code in all the mvx adapted Activities - MvxActivity, MvxTabActivity, ... There is a little cut-and-paste here, but as much code as possible is place in shared extension methods.
In previous versions, people have used this technique to bind monogame and google ads activities - eg see Insert a Monogame view inside MvvmCross monodroid Activity