简体   繁体   中英

Set Color for individual Treeview items based on data not bound to the treeview WPF

I am trying to figure out the best way to approach this. I have a treeview that is using Hierarchal data from sql server tables. Using linq to generate the dbml and then binding the data to the treeview. Here is the part I am having trouble with. Say the treeview starts and goes Categories----->Authors----->Books------>CheckedOut

So If I wanted to color each item(red) and all the parent nodes(red) where the item is overdue based on a view I created in sql server (I have four different categories to highlight based on dates stored in the db) what would be the best approach for this in C# WPF?

you can use a style trigger to trigger action when item in your tree view item meets certain condition

 <Style TargetType="TextBlock">
              <Style.Triggers>
                <DataTrigger Binding="{Binding Highlight}" Value="True">
                      <Setter Property="Background" Value="youcolor" />
                 </DataTrigger>
         </Style.Triggers>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM