【发布时间】:2020-11-02 19:37:00
【问题描述】:
如何在ListView 中绑定Label 颜色?
我无法以任何方式设置颜色,它显示标准灰色。您可以设置某种颜色(例如,红色),但我需要它根据用户的意愿动态更改。
<ListView
Style="{StaticResource ListViewStyle}"
ItemsSource="{Binding Stats}"
SelectedItem="{Binding CurrentStatParam}"
HasUnevenRows="true">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Column="0">
<Label Text="{Binding Name}" **TextColor="{Binding TextColor}"**/>
</Grid>
<Grid Column="1">
<Label Text="{Binding Value}" **TextColor="{Binding TextColor}"**/>
</Grid>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
public Color TextColor
{
get => _textColor;
set
{
_textColor = value;
OnPropertyChanged(nameof(TextColor));
}
}
<ContentPage.Content>
<Grid>
<StackLayout HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="Back Color" Margin="0,0,0,10" />
<colorPicker:ColorPickerEntry Color="{Binding BackColor}" />
<Label Text="Line color" Margin="0,0,0,10" />
<colorPicker:ColorPickerEntry Color="{Binding LineColor}" />
<Label Text="Text Color" Margin="0,0,0,10" />
<colorPicker:ColorPickerEntry Color="{Binding TextColor}" />
</StackLayout>
<!--<Button Text="Назад" Command="{Binding BackCmd}"></Button>-->
</Grid>
</ContentPage.Content>
【问题讨论】:
-
您的
TextColor属性的类型是什么?你能发布你的模型的代码吗? -
抱歉,我添加了我的代码
标签: c# xaml xamarin xamarin.forms xamarin.forms.listview