您好,我很好奇是否可以为其他属性设置PropertyChanged
吗?我的标签绑定到Bandmember
,文本绑定到名为FormattedName
的属性。
现在,它PropertyChanged
属性更改时,它将仅运行此FormattedName
事件。我在Happiness
上有一个名为Bandmember
的属性,我希望它在PropertyChanged
而不是Happiness
更新时调用FormattedName
事件。
XAML:
<ListView x:Name="dayView" ItemsSource="{Binding BandMembers}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Grid.Column="0" x:Name="dayViewFormattedNameLabel" FontSize="Small" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"
Text="{Binding FormattedName}" PropertyChanged="DayViewFormattedNameLabel_PropertyChanged" />
<Picker Grid.Column="1" FontSize="Small" Title="{Binding FormattedName, StringFormat='Select Task For {0}'}" x:Name="TaskPickerInListView"
ItemsSource="{Binding AvailableTasks}" SelectedItem="{Binding AssignedTask}" ItemDisplayBinding="{Binding TaskDescription}"
SelectedIndexChanged="TaskPickerUpdated" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
谢谢!
答案 0 :(得分:2)
啊,找到了您的新问题(我明白了您之前为什么不起作用)
我建议改用value converter。
这将把“幸福”的int值转换为颜色,然后您可以使用Label
将TextColor
的{{1}}属性绑定到Happiness
,例如:
IntToColorConverter
然后在XAML中使用它:
public class IntToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double percent = (double)((int)value) / 100;
double resultRed = Color.Red.R + percent * (Color.Green.R - Color.Red.R);
double resultGreen = Color.Red.G + percent * (Color.Green.G - Color.Red.G);
double resultBlue = Color.Red.B + percent * (Color.Green.B - Color.Red.B);
return new Color(resultRed, resultGreen, resultBlue);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}