我的約會系統的工作,我有一個包含DataTemplate中有一個切換按鈕,代表每個預約,如果預約確認的背景顏色應該改變一個列表框,這是我的列表框:WPF結合背景色不更新
添加一個新的約會時public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Brush _appointmentStatusBrush = null;
var fc = new BrushConverter();
if (value == null)
return null;
Appointment _appointment = (Appointment)value;
switch (_appointment.Status)
{
case 0:
_appointmentStatusBrush = (Brush)fc.ConvertFrom("#FFFBF7CC");
break;
case 1:
_appointmentStatusBrush = (Brush)fc.ConvertFrom("#FFFFFFFF");
break;
}
return _appointmentStatusBrush;
}
public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new System.NotImplementedException();
}
的結合的作品,但是當我更新現有的預約狀態,並刷新列表,顏色不更新!!:
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<ToggleButton Background="{Binding Converter={StaticResource AppointmentStatusColor}, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}" IsChecked="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}, Mode=FindAncestor}}">
<StackPanel Orientation="Horizontal" Width="370">
<TextBlock Text="{Binding AppointmentID}"/>
<TextBlock Text="{Binding Patient.FullName}"/>
</StackPanel>
</ToggleButton>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
背景屬性綁定到的IValueConverter
在此先感謝
有INotifyPropertyChanged的實施? –