开发者

How to sync background color of ListboxItem(s) based on ViewModel value?

开发者 https://www.devze.com 2023-03-12 06:59 出处:网络
I have a ListBox bound to a list in ViewModel. I would like to \"pin\" certain ListBoxItems with different background color based on ViewModel.

I have a ListBox bound to a list in ViewModel. I would like to "pin" certain ListBoxItems with different background color based on ViewModel. My view model looks like this, I want to highlight all the PinnedTasks in the ListBox. Seems like TypeConverter i开发者_StackOverflow社区s the best way to go, Are there any other approaches?

 class ViewModel
 {
     public List<Task> Tasks { get; set; }// Bound to ListBox
     public List<Task> PinnedTasks { get; set; } //These tasks are copy of Tasks, 
    //should be highlighted in ListBox
 }


If you can somehow modify the Tasks class to add a Pinned property or, alternatively, create a ViewModel for the Task class that contains a Pinned property, then you should be able to accomplish this with a DataTrigger when Styling/Templating your tasks.

0

精彩评论

暂无评论...
验证码 换一张
取 消