2013-11-26 31 views
0

我在我的Windows Phone 8应用程序中创建最喜欢的功能。我使用形状路径的明星,其中最喜欢的按钮位于其应该得到改变Windows Phone 8路径形状绑定通知问题

public class newreleaeslist : INotifyPropertyChanged 
{ 

    public long BookId { get; set; } 


    private string _FavouriteButton = ""; 
    public string FavouriteButton 
    { 
     get 
     { 
      return _FavouriteButton; 
     } 
     set 
     { 
      _FavouriteButton = value; 
      RaisePropertyChanged("FavouriteButton"); 
     } 
    } 

    public event PropertyChangedEventHandler PropertyChanged; 
    private void RaisePropertyChanged(string propertyName) 
    { 
     if (this.PropertyChanged != null) 
     { 
      this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
     } 
    } 
} 

我有两个列表中的一个

<Path Stroke="Yellow" Grid.Row="0" Grid.Column="0" Tag="{Binding BookId,Mode=OneWay}" Fill="{Binding FavouriteButton,Mode=OneWay}" StrokeThickness="3" StrokeStartLineCap="Round" Margin="-14,-2,0,0" StrokeEndLineCap="Round" StrokeLineJoin="Round" Data="M 0,0 l 10,0 l 5,-10 l 5,10 l 10,0 l -7,10 l 2,10 l -10,-5 l -10,5 l 2,-10 Z" Tap="Path_Tap_1" /> 

我的模型类的newrelease列表,另一个是收藏列表在全景中。 当用户点击新发布列表中的add to favourite star时,它会转到隔离存储设置中的favourites list,并将一个项目添加到收藏夹列表中。这里关于通知的一切都很好。

IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; 
     List<long> ListFavourites; 
     if (settings.Contains("ListFavourites")) 
     { 
      ListFavourites = settings["ListFavourites"] as List<long>; 
     } 
     else 
     { 
      ListFavourites = new List<long>(); 
     } 

     if (!ListFavourites.Contains(Convert.ToInt64(bt.Tag))) 
     { 
      ListFavourites.Add(Convert.ToInt64(bt.Tag)); 
     } 
     settings["ListFavourites"] = ListFavourites; 
     settings.Save(); 

1),但是当我在favourite list

2)newrelease名单的最喜爱的明星点击remove from favourite star应该改变颜色,它不会做。可能是什么问题呢?

Button bt = (Button)sender; 
     IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; 
     List<long> ListFavourites=new List<long>(); 
     if (settings.Contains("ListFavourites")) 
     { 
      ListFavourites = settings["ListFavourites"] as List<long>; 
     } 
     ListFavourites.Remove(Convert.ToInt64(bt.Tag)); 
     settings["ListFavourites"] = ListFavourites; 
     settings.Save(); 
     var item = await bookdetailsvm.GetBookDetails(Convert.ToInt64(bt.Tag),true); 
     var favouritelists = booklistvm.BooksList.FirstOrDefault(m => m.BookId == item.BookId); 

     booklistvm.BooksList.Remove(favouritelists); 
     RecordCountFavouritesList.Text = booklistvm.BooksList.Count().ToString() + " records found."; 


     foreach (var items in dashboardvm.NewReleasesbookslist) 
     { 
      if (items.BookId== item.BookId) 
      { 

       items.FavouriteButton = "Black"; // change color here 
       break; 
      } 
     } 

回答

1

你的问题是,你要一个Brush属性绑定为一个字符串,这是不允许的。

更改如下:

在模型中,

private SolidColorBrush _FavouriteButton = ""; 
public SolidColorBrush FavouriteButton 
{ 
    get 
    { 
     return _FavouriteButton; 
    } 
    set 
    { 
     _FavouriteButton = value; 
     RaisePropertyChanged("FavouriteButton"); 
    } 
} 

在你foreach

foreach (var items in dashboardvm.NewReleasesbookslist) 
{ 
    if (items.BookId== item.BookId) 
    { 
     items.FavouriteButton = new SolidColorBrush(Colors.Black); // change color here 
     break; 
    } 
} 

让我知道如何工作的。

编辑:

要使用比最初发布什么试试下面的其他颜色:

foreach (var items in dashboardvm.NewReleasesbookslist) 
    { 
     if (items.BookId== item.BookId) 
     { 
      items.FavouriteButton = new SolidColorBrush((Color)typeof(Color).GetProperty("Black").GetValue(null, null)); // change color here 
      break; 
     } 
    } 

请注意,如果你犯了一个错字或资本错误的字符串这是不行的,但它应该适用于基本颜色。

+0

好的问题是,我有一个网页API有一个string.how从字符串转换为solidcolorbrush – maztt

+0

好吧,直到有人能回答我的上面的问题。我将使用转换器 – maztt

+0

我正在更新我的答案,使用更通用的解决方案,可让您使用更多颜色 – steveg89