我有一个带有自定义ViewCell的ListView。 ViewCell包含Microcharts.Chart。我使用绑定,尝试根据某种条件(因为现在不存在图表)在ListView项目中找到一种显示特定图表的方法。
这是XAML代码的一部分:
<ListView x:Name="blocksList"
HasUnevenRows="True"
ItemsSource="{Binding MainPageBlocks}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Grid ColumnSpacing="0" RowSpacing="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40*" />
<ColumnDefinition Width="15*" />
<ColumnDefinition Width="45*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
... some elements
<forms:ChartView
x:name="LineChart"
Grid.Column="2"
Grid.Row="0"
Grid.RowSpan="3"
BackgroundColor="Transparent"
Chart="{Binding MyChart}">
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
图表条目:
private readonly List<Microcharts.Entry> _entries = new List<Microcharts.Entry>()
{
new Microcharts.Entry(200)
{
Color=SKColor.Parse("#FF0033")
},
new Microcharts.Entry(400)
{
Color=SKColor.Parse("#FF8000")
},
new Microcharts.Entry(300)
{
Color=SKColor.Parse("#FFE600")
},
new Microcharts.Entry(250)
{
Color=SKColor.Parse("#1AB34D")
},
new Microcharts.Entry(650)
{
Color=SKColor.Parse("#1A66FF")
},
new Microcharts.Entry(500)
{
Color=SKColor.Parse("#801AB3")
}
};
对于后面的代码,我尝试了不同的方法:
LineChart.BindingContext = new Microcharts.LineChart { Entries = _entries };
然后我尝试绑定ChartViews列表:
public List<Microcharts.Chart> ChartCollection { get; set; }
public Microcharts.Chart LineChart1
{
get
{
return new LineChart()
{
Entries = _entries,
LineMode = LineMode.Straight,
PointMode = PointMode.Circle,
PointSize = 20,
BackgroundColor = SKColors.Transparent,
};
}
}
public Microcharts.Chart LineChart2
{
get
{
return new LineChart()
{
Entries = _entries,
LineMode = LineMode.Straight,
PointMode = PointMode.Circle,
PointSize = 20,
BackgroundColor = SKColors.Transparent,
};
}
}
ChartCollection = new List<Chart>();
ChartCollection.Add(LineChart1);
ChartCollection.Add(LineChart2);
在编译过程中没有错误,没有chartView,其余视图都是可见的。 我应该怎么做才能在ViewCell中显示ChartView?
谢谢!