简体   繁体   中英

Can you change the style of an object based on a property within the object in WPF?

I have a class for message, and the objects are being displayed in a ListBox and there's a property for the message based on whether it's sent to or from the user. Is there a way to create two different styles and change them depending on this property?

You should create a DataTemplate for the type of the item you're displaying. In that DataTemplate, you use a DataTrigger to control how the item varies in appearance depending upon a property of the object.

Yes. use dynamic resource link text

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