Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
60
Binding Brush property to a property inside of a List of Dictionary
posted

Hi all,

I have a ViewModel class with this public property:
public List<Dictionary<int, DataModel>> Data { get; set; }

where:

DataModel{
public double X { get; set; }
public int val {get; set;}
public string Color
{
get
{
return Legend.getColor(val); //return a string like "red" or "green", etc....
}
}

---------------------------

XAML file:
<ig:XamDataChart x:Name="BarChart">

<ig:XamDataChart.Axes>
<ig:NumericXAxis x:Name="XAxis"/>
<ig:CategoryYAxis x:Name="YAxis" ItemsSource="{Binding Data}"/>
</ig:XamDataChart.Axes>

<ig:XamDataChart.Series>
<ig:StackedBarSeries
x:Name="StackedSeries" ItemsSource="{Binding Data}"
XAxis="{x:Reference XAxis}"
YAxis="{x:Reference YAxis}" Brush="{Binding [Value].Color}"> <!-- Brush property doesn't work -->
</ig:StackedBarSeries>
</ig:XamDataChart.Series>

</ig:XamDataChart>

----------------
Code-behind:

CB = new ViewModel();
BarChart.BindingContext = CB;

for (int k = 0; k < CB.maxArraySize ; k++)
{
string key = "[" + k.ToString() + "]";
StackedFragmentSeries seriesFragment = new StackedFragmentSeries();
seriesFragment.ValueMemberPath = key+"[X]";
StackedSeries.Series.Add(seriesFragment);
}
-----------------

I want to bind the Brush property of the StackedSeries to the Color property of DataModel.
I would like that each fragment of each series has a chosen color.
Actually, if I don't set the Brush property, all first fragments have the same green color, all second fragments have the same cyan color, etc... like the image in attachment.
The "behavior" of Brush property to get Color value, should be the same of ValueMemberPath.


I tried with
Brush="{Binding [Value].Color}" // List<Dictionary<int, DataModel>> where DataModel has Color property.
but it doesn't work.

Any ideas please?


Thanks to all for your support.