question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get error when I binde HexColor of Tint transformation

See original GitHub issue

Hi, I use ffimageloading in the listView with a TintTransformation, so The binding works fine for image source but for HexColor I get error for missing property. I’v defined a string property for HexColor but It dosn’t accept such property:

`<flv:FlowListView SeparatorVisibility=“None” HasUnevenRows=“true” FlowItemTapped=“OnItemTapped” FlowColumnMinWidth=“60” FlowTappedBackgroundColor=“Blue” FlowTappedBackgroundDelay=“50” FlowItemsSource=“{Binding Items}” x:Name=“listView”>

<flv:FlowListView.FlowColumnTemplate>
  <DataTemplate>
    <Grid Padding="3">
      <Grid.RowDefinitions>
        <RowDefinition Height="*" />
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
      </Grid.ColumnDefinitions>
      
      <ffimageloading:CachedImage x:Name="selectIcon" WidthRequest="50" HeightRequest="50" DownsampleToViewSize="true"
                                  Source = "{Binding IconPath, Converter={StaticResource ImageSourceConverter}}">
        <ffimageloading:CachedImage.Transformations>
          <fftransformations:TintTransformation HexColor="{Binding HexColor}" EnableSolidColor="true"/>
        </ffimageloading:CachedImage.Transformations>
      </ffimageloading:CachedImage>
      
    </Grid>
  </DataTemplate>
</flv:FlowListView.FlowColumnTemplate>

</flv:FlowListView>

My model is: public class Icons { public string IconPath { get; set; } public string HexColor { get; set; } }

any idea? Thanks

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

26reactions
EmmanVazzcommented, Feb 15, 2017

Oh HexColor is not defined as a bindable property.

You can make a PR to make it a bindable property, we just made a custom class to wrap that and have a bindable property.

public class TintedCachedImage : CachedImage
	{
		public static BindableProperty TintColorProperty = BindableProperty.Create(nameof(TintColor), typeof(Color), typeof(TintedCachedImage), Color.Transparent, propertyChanged: UpdateColor);

		public Color TintColor
		{
			get { return (Color)GetValue(TintColorProperty); }
			set { SetValue(TintColorProperty, value); }
		}

		private static void UpdateColor(BindableObject bindable, object oldColor, object newColor)
		{
			var oldcolor = (Color)oldColor;
			var newcolor = (Color)newColor;

			if (!oldcolor.Equals(newcolor))
			{
				var view = (TintedCachedImage)bindable;
				var transformations = new System.Collections.Generic.List<ITransformation>() {
					new TintTransformation((int)(newcolor.R * 255), (int)(newcolor.G * 255), (int)(newcolor.B * 255), (int)(newcolor.A * 255)) {
						EnableSolidColor = true
					}
				};
				view.Transformations = transformations;
			}
		}
	}
5reactions
MosCDcommented, Feb 27, 2018

Well I managed to find a solution for the problem I posted in the recent comment

`public class TintedCachedImage : CachedImage { public static BindableProperty TintColorProperty = BindableProperty.Create(nameof(TintColor), typeof(Color), typeof(TintedCachedImage), Color.Transparent, propertyChanged: UpdateColor);

    public Color TintColor
    {
        get { return (Color)GetValue(TintColorProperty); }
        set { SetValue(TintColorProperty, value); }
    }

    private static void UpdateColor(BindableObject bindable, object oldColor, object newColor)
    {
        var oldcolor = (Color)oldColor;
        var newcolor = (Color)newColor;

        if (!oldcolor.Equals(newcolor))
        {
            var view = (TintedCachedImage)bindable;
            var transformations = new System.Collections.Generic.List<ITransformation>() {
                new TintTransformation((int)(newcolor.R * 255), (int)(newcolor.G * 255), (int)(newcolor.B * 255), (int)(newcolor.A * 255)) {
                    EnableSolidColor = true
                }
            };
            view.Transformations = transformations;
        }
    }

    //To Support SVG
    public static BindableProperty SvgSourceProperty = BindableProperty.Create(nameof(TintColor), typeof(string), typeof(TintedCachedImage), null, propertyChanged: UpdateSvg);
    public string SvgSource
    {
        get { return (string)GetValue(SvgSourceProperty); }
        set { SetValue(SvgSourceProperty, value); }
    }

    private static void UpdateSvg(BindableObject bindable, object oldVal, object newVal)
    {
        var _instance = bindable as TintedCachedImage;
        _instance.Source = SvgImageSource.FromFile((string)newVal);
    }
}`

I added a custom property to enable directly loading svg image from xml

usage

<local:TintedCachedImage Grid.Row="0" SvgSource="reset.svg" TintColor="{StaticResource BrandColor}" />

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I convert a Color to a Brush in XAML?
The Fill property takes a Brush object, so I need an IValueConverter object to perform the conversion. Is there a built-in converter in...
Read more >
Color state list resource
A ColorStateList is an object you can define in XML and apply as a color that actually changes colors depending on the state...
Read more >
PIXI.utils
Converts a hexadecimal color number to an [R, G, B] array of normalized floats (numbers from 0.0 to 1.0). Name, Type, Attributes, Default,...
Read more >
Functions
Bind the evaluation of a ruleset to each member of a list. Parameters. list - a comma or space separated list of values....
Read more >
Color picker | Substance 3D Painter
The color picker allows to set a color to paint or project on the mesh. It can be used to pick colors from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found