我在我的Windows Phone 8应用程序中创建了最喜欢的功能。我正在使用形状路径作为明星
<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" />
我喜欢的按钮所在的模型类,应该更改
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));
}
}
}
我有两个列表,一个是新发布列表,另一个是全景图中的收藏夹列表。
当用户点击新发布列表中的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)但是当我点击remove from favourite star
favourite list
时
2)新发布列表中最喜欢的明星应该改变它不会做的颜色。可能是什么问题?
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;
}
}
答案 0 :(得分: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;
}
}
请注意,如果您在字符串中输入拼写错误或大写错误,这将无效,但它应该适用于基本颜色。