【发布时间】:2021-10-18 04:36:36
【问题描述】:
我正在使用 Xamarin 表单。
我有一个包含几个列表视图的简单视图。整个视图有一个带有视图模型的 BindingContext。视图模型类包含一个 BackgroundColor。 问题:如何从列表视图的 dataTemplate 中访问 BackgroundColor 属性。
ViewModel.cs
public class TestViewModel {
public System.Drawing.Color BackgroundColor { get; set; }
public List<Employee> Employees { get; set; }
}
上述类的一个实例为视图设置了一个BindingContext 查看.xaml
<ContextPage.... >
....
<listview ItemsSource="{Binding Employees}"...
<DataTemplate>
<Grid BackgroundColor="{Binding BackgroundColor}">
</ContentPage>
上述网格的背景不起作用,因为当前上下文现在位于 Employee 集合中。那么如何在列表视图中访问视图模型中的“BackgroundColor”。
【问题讨论】:
标签: c# xaml xamarin.forms binding