vendredi 20 février 2015

Different Images for Radio Buttons in Group by mvvmcross

I'm using mvvmcross for android app. I'm trying to create group of dynamic radiobuttons with specific image for each button. Everything is going well except there are no images.


Parent axml:



<Mvx.MvxRadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textLanguage"
android:layout_alignLeft="@id/textLanguage"
android:layout_marginLeft="20dp"
local:MvxItemTemplate="@layout/radioitem"
local:MvxBind="ItemsSource LanguageImageList;SelectedItem SelectedLanguage" />


RadioItem.axml:



<RadioButton xmlns:android="http://ift.tt/nIICcg"
xmlns:local="http://ift.tt/GEGVYd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
local:MvxBind="Text Key; Bitmap Value, Converter=MvxImageConverter" />


My converter:



public class MvxImageConverter : MvxValueConverter<string, Bitmap>
{
protected override Bitmap Convert(string value, Type targetType, object parameter, CultureInfo cultureInfo)
{
var imageLoader = Mvx.Resolve<IMvxLocalFileImageLoader<Bitmap>>();
MvxImage<Bitmap> image = imageLoader.Load(value, true);
return image.RawImage;
}
}


In debugger convertor method is invoked and image.RawImage is not null or empty.


And finally viewModel:



private string _selectedLanguage;
public string SelectedLanguage
{
get { return _selectedLanguage; }
set
{
_selectedLanguage = value;
RaisePropertyChanged(() => SelectedLanguage);
LanguageChanged();
}
}

public Dictionary<string, string> LanguageImageList
{
get { return new Dictionary<string, string>() { { "US", "res:lang_us_small" }, { "UK", "res:lang_uk_small" }, { "FR", "res:lang_fr_small" }, { "GE", "res:lang_ge_small" } }; }
}


I tried different binding keywords instead of "Bitmap": "DrawableId", "DrawableName", "Image", "ImageUrl", "Button", "Style". No luck. In output I always see message that value could not be bound to specified keyword.


If I create static radio buttons in parent axml and give specific link to image to each radio button, I can see images but binding does not work i.e. setter of SelectedLanguage is not invoked. BTW I don't like this solution.


Is it possible in mvvmcross create a dynamic (or at least static) group of radio buttons with specific image for each button?


Desired picture: http://ift.tt/1E9Zap8


Aucun commentaire:

Enregistrer un commentaire