iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
Dear crosslight developer.
I'm writting to you because I want to bind the background color in a gridview cell, using hexadecimal color with is saving in a property model's.
My model have a Color property and my ViewModel is ListViewModel<Model>, and it draw a gridview. Each one of those cells should bind a model color property with a cell background color.
Could you tell me if I need a custom bindingprovider? How can I do it?
Thank you very much.
Hi Cristobal,First of all, you must create a Custom GridViewCell, because our GridViewCell doesn't have id that can be used to bind with the cell background, so you must make a Custom one including the id inside the layout.
Please remember that you only need this code inside your view model to access data from model and repository or local List<> : this.SourceItems = this.Repository.GetAll().ToObservable();
Next to connect with the background color, there are however there are two method to access the value from the data
First Method is you can manipulate your model by adding this:
public StyleAttributes ColorStyle { get { return new StyleAttributes(){ BackgroundColor=(this.Color == Red)?Color.FromArgb(0xff,0xff,0x00,0x00):Color.FromArgb(0xff,0xff,0xff,0xff) }; } }
Note you can change Color.FromArgb with our premade color using for example: Colors.Red or Colors.Transparent, also remember to add 0x before hex code because it only accept byteThen inside your binding provider you can add:
itemBinding.AddBinding("YourCellBackgroundID", BindableProperties.StyleAttributesProperty, new BindingDescription("ColorStyle"));
This could be done because when you can call List/Grid type you can also access your model from thereAnother method you can use is converter:Add this inside your binding provider:
itemBinding.AddBinding("YourCellBackgroundID", BindableProperties.StyleAttributesProperty, new BindingDescription("Color"){ Converter = new ColorConverter()});
Make new file named ColorConverter with class ColorConverter and insert this inside:
public class ColorConverter: IValueConverter { #region IValueConverter implementation public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is String) { int CatColor = (String)value; if (CatColor == "Red") { StyleAttributes style = new StyleAttributes(); style.BackgroundColor = Colors.Red; return style; } else { StyleAttributes style = new StyleAttributes(); style.BackgroundColor = Colors.White; return style; } } return null; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new System.NotImplementedException(); } #endregion }
Connect your binding provider with this converterSo in conclusion, i think the second method is more cleaner and doesn't manipulate the model too much... The only file you actually need to changes is just the Layout and Binding Provider (also model or converter)You can also see this kind of implementation in our samples: http://git.intersoftpt.com/projects/CROS/repos/samples/browse/MyInventory
Hope that helps :)Best Regards,Arief
Thank you very much!! This method is OK
Glad it work!,Should you need further assistance or run into any problems regarding our controls, feel free to post it into our forum. We would be happy to assist you again!
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname