2
votes

I have bind the box clour with the value ( in the view model) and in xaml as below in xaml

<BoxView  Grid.Row="2" Color="{Binding ParentContext.BoColor,Source={x:Reference dashboardThree}}" />

and in modelview as below

   public string BoColor { get; set; } = "#000080";

so the above code shows the blue color every time the app runs , The problem is that i have 10 boxes creted dynamically in the list view and all 10 boxes shows the above color ( since that i have only 1 list-view to show my jason objects and it dynamically creates 10,15 etc boxes ) , so is their any way that i can add different 10 colors ( random or defined hexa colours) for the each different boxes ?? thank you in advance for your support.

1

1 Answers

0
votes

It really depends upon if you need those colors to be repeatable for each of those BoxViews.

Here is an example of just randomly assigning a color.

Random random = new Random();
public string BoColor
{
    get
    {
        return String.Format("#{0:X6}", random.Next(0x1000000));
    }
}

Example:

<StackLayout>
    <Label Text="StackOverflow" BackgroundColor="{Binding BoColor}"/>
    <Label Text="StackOverflow" BackgroundColor="{Binding BoColor}"/>
    <Label Text="StackOverflow" BackgroundColor="{Binding BoColor}"/>
    <Label Text="StackOverflow" BackgroundColor="{Binding BoColor}"/>
    <Label Text="StackOverflow" BackgroundColor="{Binding BoColor}"/>
</StackLayout>

enter image description here