[英]Items Data Binded to LongListSelector/Listbox not showing in windows phone 8 local database
[英]Changing an item color of a LongListSelector or Listbox that is binded
我一直在嘗試更改從綁定中獲取顏色的ListBox
中TextBlock
的顏色。
<TextBlock Text="{Binding Title}" TextWrapping="Wrap" Foreground="{Binding ItemColor, Converter={StaticResource ColorConverter}}" Style="{StaticResource posttitle}" d:LayoutOverrides="Width"/>
這是在初始渲染期間工作的轉換器:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null)
return new SolidColorBrush(Colors.Red);
Color colorValue = (Color)value;
return new SolidColorBrush(colorValue);
}
在SelectionChanged事件期間,我為該項分配了新的顏色,如下所示:
private void List_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var listbox = (LongListSelector)sender;
if (listbox.SelectedItem == null)
return;
MyItem item = (MyItem)listbox.SelectedItem;
if (item.Clicked)
{
// Change some value
item.Clicked = true;
item.ItemColor = new Color() { A = 0xFF, R = 0xBD, G = 0xB7, B = 0x6B };
}
}
如果我放置一個斷點並檢查數據上下文,則可以看到源中的值已更改,但從外觀上看LongListSelector
並沒有改變外觀。 綁定是綁定到ObservableCollection
並且ItemColor
會通知更改。
任何幫助表示贊賞。
您還沒有給予足夠的信息,但根據您所提供的代碼,它看起來像時item.ItemColor
設置為PropertyChanged事件ItemColor
沒有被解雇。
MyItem
應該實現INotifyPropertyChanged
並調用PropertyChanged(this, new PropertyChangedEventArgs("ItemColor"))
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.