Issue
How to bind a Label
color in a ListView
?
I can't set the color in any way, it shows standard gray. You can set a certain color (for example, red), but I need it to change dynamically, from the user's desire.
<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>
Solution
The problem is in your ItemsSource. There is no property named "TextColor" here. You can use following code to escape from this situation:
<Label Text="{Binding Name}" TextColor="{Binding Source={x:Reference This}, Path=BindingContext.TextColor}"/>
Answered By - Sergey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.